ef-code-first

One to many recursive relationship with Code First

不羁的心 提交于 2021-01-27 04:27:05
问题 I am trying to implement a simple self referencing relationship with EF 6.1.2 Code First. public class Branch { [Key] public int Id { get; set; } [Required] public string Name { get; set; } public int? ParentId { get; set; } [ForeignKey("ParentId")] public virtual Branch Parent { get; set; } public ICollection<Branch> Children { get; set; } // direct successors } In my application I have exactly one root branch. And except for this single root branch, every branch has exactly one parent (the

One to many recursive relationship with Code First

萝らか妹 提交于 2021-01-27 04:23:13
问题 I am trying to implement a simple self referencing relationship with EF 6.1.2 Code First. public class Branch { [Key] public int Id { get; set; } [Required] public string Name { get; set; } public int? ParentId { get; set; } [ForeignKey("ParentId")] public virtual Branch Parent { get; set; } public ICollection<Branch> Children { get; set; } // direct successors } In my application I have exactly one root branch. And except for this single root branch, every branch has exactly one parent (the

How to MAP select stored procedure in Entity Framework 6 code-first approach?

懵懂的女人 提交于 2021-01-18 04:47:08
问题 For example when we write protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<tblError>().MapToStoredProcedures(); } Then it will create 3 stored procedures in the database with the names of tblError_Delete , tblError_Insert , tblError_Update My question is about tblError_Select : how to map a stored procedure that is used to execute select queries? I want EF to be generate tblError_Select along with preceding 3 stored procedures. I want to do CRUD

Mapping foreign key to non primary surrogate key column in EF code first

余生长醉 提交于 2021-01-02 06:16:12
问题 public class A { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public virtual int Aid { get; set; } public virtual ICollection<B> B { get; set; } } public class B { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public virtual int Bid { get; set; } [Key] [Column(Order = 0)] [Required] Public virtual string BName {get ; set} [Key] [Column(Order = 1)] [Required] public virtual int Aid { get; set; } [ForeignKey("Aid")] public virtual A A { get; set; } public virtual ICollection<C>