//Class Defines public class TableA: IdEntity //Id Property define there { private ICollection<TableB> _tableBList; public virtual string Name { get; set; } public virtual ICollection<TableB> TableBList { get { return _tableBList ?? (_tableBList = new List<TableB>()); } protected set { _tableBList = value; } } } public class TableB: IdEntity //Id Property define there { public virtual string Name { get; set; } } public class TableC: IdEntity //Id Property define there { public virtual int TableAId{ get; set; } public virtual int TableBId{ get; set; } public virtual TableA TableA{ get; set; } public virtual TableB TableB{ get; set; } } // Mapping class public class TableAMap : EntityTypeConfiguration<TableA> { public TableAMap() { this.ToTable("TableA"); this.HasKey(x => x.Id); this.Property(x => x.Name).IsRequired().HasMaxLength(100); } } public class TableBMap : EntityTypeConfiguration<TableB> { public TableBMap() { this.ToTable("TableB"); this.HasKey(x => x.Id); this.Property(x => x.Name).IsRequired().HasMaxLength(100); } } public class TableCMap: EntityTypeConfiguration<TableC> { public TableCMap() { this.ToTable("TableC"); this.HasKey(x => x.Id); this.HasRequired(x => x.TableB) .WithMany() .HasForeignKey(x => x.TableBId); this.HasRequired(x => x.TableA) .WithMany(x => x.TableBList) .HasForeignKey(x => x.TableAId); } }
var bObject = GetTableBById(1); var cObject = bObject.TableC;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)