How can I configure relationships between three tables to get all related data?
I have the following models (and the same tables in database):
public class Client
{
public Guid ClientId { get; set; }
public string FirstName { get; set; }
public virtual ClientCard ClientCard { get; set; }
}
public class Card
{
public Guid CardId { get; set; }
public string Number { get; set; }
public virtual ClientCard ClientCard { get; set; }
}
public class ClientCard
{
public Guid ClientCardId { get; set; }
public Guid CardId { get; set; }
public Guid ClientId { get; set; }
public virtual Client Client { get; set; }
public virtual Card Card { get; set; }
}
And the following OnModelCreating method:
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.Conventions.Remove<PluralizingTableNameConvention>();
...
builder.Entity<ClientCard>()
.HasKey(x => x.ClientCardId);
builder.Entity<ClientCard>()
.HasRequired(x => x.Client)
.WithRequiredPrincipal(x => x.ClientCard);
builder.Entity<ClientCard>()
.HasRequired(x => x.Card)
.WithRequiredPrincipal(x => x.ClientCard);
base.OnModelCreating(builder);
}
But the results return without related data. Why?
For your code please try something like:
public class Client
{
public Guid ClientId { get; set; }
public string FirstName { get; set; }
public virtual ICollection<ClientCard> ClientCard { get; set; }
}
public class Card
{
public Guid CardId { get; set; }
public string Number { get; set; }
public virtual ICollection<ClientCard> ClientCard { get; set; }
}
public class ClientCard
{
public Guid ClientCardId { get; set; }
public Guid CardId { get; set; }
public Guid ClientId { get; set; }
public virtual Client Client { get; set; }
public virtual Card Card { get; set; }
}
And mapping:
builder.Entity<Client>()
.HasKey(t => t.ClinetID);
....
builder.Entity<Client>()
.HasMany(a => a.ClientCard)
.WithRequired(p => p.Client)
.HasForeignKey(p => p.ClientID);
For Card
....
builder.Entity<Card>()
.HasMany(a => a.ClientCard)
.WithRequired(p => p.Card)
.HasForeignKey(p => p.CardID);
But I think the best way is to create a separate map-file for each entities
Now I am using the following models:
public class Client
{
public Guid ClientId { get; set; }
public string FirstName { get; set; }
public Guid? CardId { get; set; }
public virtual Card Card { get; set; }
}
public class Card
{
public Guid CardId { get; set; }
public string Number { get; set; }
//public virtual Client Client { get; set; }
}
and the following OnModelCreating method:
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.Conventions.Remove<PluralizingTableNameConvention>();
...
builder.Entity<Client>()
.HasOptional(x => x.Card)
//.WithOptionalPrincipal(x=> x.Client)
//or
//.WithOptionalDependent(x=> x.Client)
;
base.OnModelCreating(builder);
}
All clients return with related data(if exists). But if I want to get ralated data with Card object and uncomment public virtual Client Client { get; set; } and WithOptionalPrincipal/WithOptionalDependent I always get on of these SqlException: "invalid column name 'Client_ClientId'" (if WithOptionalPrincipal is used) OR "invalid column name 'Card_CardId'" (if WithOptionalDependent is used)
I finally found a solution for my case.
First, I have removed CardId from Client class.
Second, I have changed my OnModelCreating method:
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.Conventions.Remove<PluralizingTableNameConvention>();
...
builder.Entity<Client>()
.HasOptional(x => x.Card)
.WithOptionalDependent(x => x.Client)
.Map(x => x.MapKey("CardId"))
.WillCascadeOnDelete(false);
builder.Entity<Card>()
.HasOptional(x => x.Client)
.WithOptionalPrincipal(x => x.Card)
.WillCascadeOnDelete(false);
base.OnModelCreating(builder);
}
Related
I'm a beginner and trying to make many to many relationships between two classes with one relation ship class. But I got no result. How can I solve the issue?
I have used the post and the Example from EF core documentation as a basis, but without success.
table design:
Role
Users
with FK for UserID and RoleID
UserRoles
code:
public class User
{
public string ID { get; set; }
public string Username { get; set; }
public virtual ICollection<UserRoles> Roles { get; set; }
}
public class Role
{
public string ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<UserRoles> Users { get; set; }
}
public class UserRoles
{
public string ID { get; set; }
public string UserID { get; set; }
public virtual User User { get; set; }
public string RoleID { get; set; }
public virtual Role Role { get; set; }
}
Fluent API:
public class ApplicationUserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> entity)
{
entity.HasKey(x => x.ID);
entity.HasMany(user => user.Roles)
.WithOne(role => role.User)
.HasForeignKey(x => x.UserID);
}
}
public class RoleConfiguration : IEntityTypeConfiguration<Role>
{
public void Configure(EntityTypeBuilder<Role> entity)
{
entity.HasKey(x => x.ID);
entity.HasMany(role => role.Users)
.WithOne(user => user.Role)
.HasForeignKey(x => x.RoleID);
}
}
public class IdentifyDBContext : DbContext
{
public IdentifyDBContext(DbContextOptions<IdentifyDBContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new ApplicationUserConfiguration());
modelBuilder.ApplyConfiguration(new RoleConfiguration());
}
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<UserRoles> UserRoles { get; set; }
}
Please let me know if you need any further information.
Thanks and best regards
fs
I dont know alot of English Lang But I will try...
so i have this error
Introducing FOREIGN KEY constraint 'FK_Conversation_User_Users_UserID' on table 'Conversation_User' may cause
cycles or multiple cascade paths.
Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
and my code is:
AppDB:
public class AppDB : DbContext
{
public AppDB() : base() { }
public AppDB(DbContextOptions<AppDB> options) : base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(#"Server=(LocalDB)\MSSQLLocalDB;Database=TetraMessangerDB;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Conversation_User>().HasKey(cu => new { cu.ConversationID, cu.UserID });
modelBuilder.Entity<Message_Media>().HasKey(mm => new { mm.MediaID, mm.MessageID });
modelBuilder.Entity<Participant>().HasKey(p => new { p.UserID, p.GroupID });
}
public DbSet<User> Users { get; set; }
public DbSet<Conversation_User> Conversation_User { get; set; }
public DbSet<Conversation> Conversation { get; set; }
}
User:
public class User
{
public User()
{
Participants = new List<Participant>();
SenMessages = new List<Message>();
ResMessages = new List<Message>();
}
public int UserID { get; set; }
public string Name { get; set; }
public string Password { get; set; }
public string Bio { get; set; }
public string EMail { get; set; }
public string UserName { get; set; }
public bool Activate { get; set; }
public int MediaID { get; set; }
public virtual Media Media { get; set; }
public virtual UserStatus UserStatus { get; set; }
public virtual List<Participant> Participants { get; set; }
[InverseProperty("SenderUser")]
public virtual List<Message> SenMessages { get; set; }
[InverseProperty("ReciverUser")]
public virtual List<Message> ResMessages { get; set; }
public virtual List<Conversation_User> Conversation_User { get; set; }
}
Conversation:
public class Conversation
{
public Conversation()
{
Conversation_User = new List<Conversation_User>();
}
public int ConversationID { get; set; }
public DateTime StartDate { get; set; }
public int MediaID { get; set; }
public virtual Media Media { get; set; }
public virtual List<Conversation_User> Conversation_User { get; set; }
}
Conversation_User:
public class Conversation_User
{
public int ConversationID { get; set; }
public virtual Conversation Conversation { get; set; }
public int UserID { get; set; }
public virtual User User { get; set; }
}
so I see alot of same quastion but i dont understand ...
i dont have multiple path so why i get this error.
can some body explain this.
Note: I have alot of entitys with the same problem in Many-To-Many Relationship but if i can solve this, I will understand how to solve thim.
and thanks for helping me.
Edit: I tried this but still getting the same
modelBuilder.Entity<Conversation_User>()
.HasOne(pt => pt.User)
.WithMany(p => p.Conversation_User)
.HasForeignKey(pt => pt.UserID)
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<Conversation_User>()
.HasOne(pt => pt.Conversation)
.WithMany(p => p.Conversation_User)
.HasForeignKey(pt => pt.ConversationID)
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
I'm trying to straighten out the EF-Model for a junctiontable OwnerCows.dbo.
There's a class Cow with an Id, a class Owner with an Id and i want to reference them both in a OwnerCows-table that has only an OwnerCowId, a CowId(FK) and a OwnerId(FK).
The error I'm getting is:
Cannot create a relationship between 'Owner.OwnerCows' and 'OwnerCow.Owner', because there already is a relationship between 'Owner.CowOwners' and 'OwnerCow.Owner'. Navigation properties can only participate in a single relationship.
Does it mean I have a circular reference? How can I solve this?
the Owner.cs:
public class Owner : EntityBase<Guid>
{
public string Name { get; set; }
[NotMapped]
public ICollection<Cow> Cows { get; set; }
= new List<Cow>();
public virtual List<OwnerCow> CowOwners { get; set; }
public Cow Cow { get; set; }
}
the Cow.cs:
public class Cow : EntityBase<Guid>
{
[MaxLength(50)]
public string Name { get; set; }
public string Breed { get; set; }
public string Color { get; set; }
public ICollection<Entities.Weight> Weights { get; set; }
= new List<Weight>();
public ICollection<Vaccination> Vaccinations { get; set; }
= new List<Vaccination>();
[NotMapped]
public ICollection<Owner> CowOwners { get; set; }
= new List<Owner>();
public List<OwnerCow> OwnerCows { get; set; }
}
the OwnerCows.cs:
public class OwnerCow
{
public Guid OwnerCowId { get; set; }
public Cow Cow { get; set; }
public Guid CowId { get; set; }
public Owner Owner { get; set; }
public Guid OwnerId { get; set; }
}
the Context-class:
public class DogFaceContext : DbContext
{
public DogFaceContext()
{
}
public DogFaceContext(DbContextOptions<DogFaceContext> options)
: base(options)
{
Database.Migrate();
}
//Entity Tables
public virtual DbSet<Owner> Owners { get; set; }
public virtual DbSet<Cow> Cows { get; set; }
public virtual DbSet<Vaccination> Vaccination { get; set; }
public virtual DbSet<Weight> Weight { get; set; }
//Junction Tables
public virtual DbSet<OwnerCow> OwnerCows { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Cow>().HasMany(x => x.CowOwners).WithOne(x => x.Cow);
builder.Entity<Owner>().HasMany(u => u.CowOwners).WithOne(X => X.Owner);
builder.Entity("DogFace.API.Entities.OwnerCow", b =>
{
b.HasOne("DogFace.API.Entities.Cow", "Cow")
.WithMany("OwnerCows")
.HasForeignKey("CowId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("DogFace.API.Entities.Owner", "Owner")
.WithMany("OwnerCows")
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Restrict);
});
}
}
Can I get it to work with this design? Is it possible with EFCore? Any other suggestions? Thanks!
You model is very complex and has some unnecessary relationships like Owner.Cows since you decide to configure many-to-many relationship.You could just get Owner's cows using
var owner = new Owner();
List<Cow> cows = owner.OwnerCows.Where(oc => oc.OwnerId == owner.Id)
.Select(oc => oc.Cow)
.ToList();
1.To have OwnerCowId, a CowId(FK) and a OwnerId(FK) in OwnerCows, refer to my below configuration:
public class Owner : EntityBase<Guid>
{
public string Name { get; set; }
public virtual List<OwnerCow> OwnerCows { get; set; }
}
public class Cow : EntityBase<Guid>
{
[MaxLength(50)]
public string Name { get; set; }
public string Breed { get; set; }
public string Color { get; set; }
public ICollection<Entities.Weight> Weights { get; set; } = new List<Weight>();
public ICollection<Vaccination> Vaccinations { get; set; }= new List<Vaccination>();
public List<OwnerCow> OwnerCows { get; set; }
}
public class OwnerCow
{
[Key]
public Guid OwnerCowId { get; set; }
public Cow Cow { get; set; }
public Guid CowId { get; set; }
public Owner Owner { get; set; }
public Guid OwnerId { get; set; }
}
DbContext:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<OwnerCow>()
.HasOne(oc => oc.Cow)
.WithMany(c => c.OwnerCows)
.HasForeignKey(oc => oc.CowId);
builder.Entity<OwnerCow>()
.HasOne(oc => oc.Owner)
.WithMany(o => o.OwnerCows)
.HasForeignKey(oc => oc.OwnerId);
}
}
In this case, your OwnerCowId id the primary key for your OwnerCows table which is not reasonable and it may have the same record of CowId,OwnerId for OwnerCows.
2.Usually,the primary key for the join table is a composite key comprising both of the foreign key values,I suggest that you could use composite key for your OwnerCow:
public class OwnerCow
{
public Cow Cow { get; set; }
public Guid CowId { get; set; }
public Owner Owner { get; set; }
public Guid OwnerId { get; set; }
}
DbContext:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<OwnerCow>()
.HasKey(oc => new { oc.OwnerId, oc.CowId });
builder.Entity<OwnerCow>()
.HasOne(oc => oc.Cow)
.WithMany(c => c.OwnerCows)
.HasForeignKey(oc => oc.CowId);
builder.Entity<OwnerCow>()
.HasOne(oc => oc.Owner)
.WithMany(o => o.OwnerCows)
.HasForeignKey(oc => oc.OwnerId);
}
}
Refer to https://www.learnentityframeworkcore.com/configuration/many-to-many-relationship-configuration
Fix context builder:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Cow>().HasMany(x => x.CowOwners).WithOne(x => x.Cow);
builder.Entity<Owner>().HasMany(u => u.Cows).WithOne(X => X.Owner); // Cows instead of CowOwners
builder.Entity("DogFace.API.Entities.OwnerCow", b =>
{
b.HasOne("DogFace.API.Entities.Cow", "Cow")
.WithMany("OwnerCows")
.HasForeignKey("CowId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("DogFace.API.Entities.Owner", "Owner")
.WithMany("CowOwners") // CowOwners instead of OwnerCows
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Restrict);
});
}
... or fix property names in classes:
public class Owner : EntityBase<Guid>
{
public string Name { get; set; }
[NotMapped]
public ICollection<Cow> CowOwners { get; set; } // CowOwners instead of Cows ?
= new List<Cow>();
public virtual List<OwnerCow> OwnerCow { get; set; } // OwnerCow instead of CowOwners ?
public Cow Cow { get; set; }
}
but don't forget to change dbcontext builder with fixed property names.
How fix the problem ?
Error Message
In Entity Framework Core, I'm attempting to create a system with 4 Db Models - User,UserProfile,Review, ApplicationInfo.
I tried a lot of things, well, I don’t understand the concept of how to fix the situation, I clearly gave cascade in modelOnCreate
Model User.
public class User
{
public int Id { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Token { get; set; }
public UserProfile UserProfile { get; set; }
}
Model UserProfile
public class UserProfile
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public int UserId { get; set; }
public User User { get; set; }
public IEnumerable<ApplicationInfo> ApplicationInfos { get; set; }
public IEnumerable<Review> Reviews { get; set; }
}
Model Review
public class Review
{
public int Id { get; set; }
public string Text { get; set; }
public string ImageLocation { get; set; }
public string Version { get; set; }
public string Rate { get; set; }
//One(AppInfo) to Many(Review)
public int ApplicationInfoId { get; set; }
public ApplicationInfo ApplicationInfo { get; set; }
//One(UserProfile) to Many(Review)
public int UserProfileId { get; set; }
[Required]
public UserProfile UserProfile { get; set; }
}
Model ApplicationInfo
public class ApplicationInfo
{
[Key]
public int Id { get; set; }
[Required]
public string ApplicationId { get; set; }
[Required]
public string AppName { get; set; }
[Required]
public string PublisherEmail { get; set; }
public string Genre { get; set; }
public string Price { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string IconUrl { get; set; }
public string PublisherName { get; set; }
public string AllRatingCount { get; set; }
public string AllRating { get; set; }
//One(UserProfile) To Many(AppInfo)
public int UserProfileId { get; set; }
public UserProfile UserProfile { get; set; }
public IEnumerable<Review> Reviews { get; set; }
}
OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().
HasOne<UserProfile>(s=>s.UserProfile).
WithOne(s=>s.User).
HasForeignKey<UserProfile>(s=>s.UserId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<ApplicationInfo>()
.HasOne<UserProfile>(s => s.UserProfile)
.WithMany(s => s.ApplicationInfos)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Review>()
.HasOne<UserProfile>(s => s.UserProfile)
.WithMany(s => s.Reviews)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Review>()
.HasOne<ApplicationInfo>(s => s.ApplicationInfo)
.WithMany(s => s.Reviews)
.OnDelete(DeleteBehavior.Cascade);
}
Just Change OnModelCreating and change OnDelete for Review and AppInfo to Restrict(No Action)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasOne<UserProfile>(s => s.Profile)
.WithOne(s => s.User)
.HasForeignKey<UserProfile>(s=>s.UserId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<ApplicationInfo>()
.HasOne<UserProfile>(s => s.UserProfile)
.WithMany(s => s.ApplicationInfos)
.HasForeignKey(s => s.UserProfileId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Review>()
.HasOne<UserProfile>(s => s.UserProfile)
.WithMany(s => s.Reviews)
.HasForeignKey(s => s.UserProfileId)
.OnDelete(DeleteBehavior.Restrict);
modelBuilder.Entity<Review>()
.HasOne<ApplicationInfo>(s => s.ApplicationInfo)
.WithMany(s => s.Reviews)
.HasForeignKey(s => s.ApplicationInfoId)
.OnDelete(DeleteBehavior.Restrict);
base.OnModelCreating(modelBuilder);
}
I am getting all the related tables populated (multiple times /circular/loop) even for a simple include of 2 tables query..
Here are my DB details.
public interface IPhaniDbContext
{
DbSet<Data_CustomerDetail> CustomerDetails { get; set; }
DbSet<Data_DisplayStyle> DisplayStyles { get; set; }
DbSet<Data_ResumeDetail> ResumeDetails { get; set; }
int Save();
Task<int> SaveChangesAsync();
Database Database { get; }
DbEntityEntry Entity(object entity);
DbSet<TEntity> Set<TEntity>() where TEntity : class;
}
public class PhaniDbContext :DbContext , IPhaniDbContext
{
public PhaniDbContext() : base(ConnectionString())
{
Configuration.LazyLoadingEnabled = false;
}
private static string ConnectionString()
{
return ConfigurationManager.AppSettings[Constants.Appsetting_PhaniDbConnectionString];
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.AddFromAssembly(Assembly.GetAssembly(GetType()));
modelBuilder.Entity<Data_CustomerDetail>()
.HasMany(x => x.ResumeDetails).WithRequired(e => e.CustomerDetail).WillCascadeOnDelete(false);
//modelBuilder.Entity<Data_CustomerDetail>()
// .Map(x => x.Requires("ResumeDetails")).Ignore(e => e.ResumeDetails)
// .Map(x => x.Requires("DisplayStyle")).Ignore(e => e.ResumeDetails);
modelBuilder.Entity<Data_DisplayStyle>()
.HasMany(x => x.ResumeDetails).WithRequired(e => e.DisplayStyle).WillCascadeOnDelete(false);
}
public int Save()
{
return base.SaveChanges();
}
public DbEntityEntry Entity(object entity)
{
throw new NotImplementedException();
}
//TODO: No-Urget-Over ride Save just to know. and all other possible overrides.
public virtual DbSet<Data_CustomerDetail> CustomerDetails { get; set; }
public virtual DbSet<Data_DisplayStyle> DisplayStyles { get; set; }
public virtual DbSet<Data_ResumeDetail> ResumeDetails { get; set; }
}
Query:
_phaniDbContext.CustomerDetails
.Include(x => x.ResumeDetails)
.Include(x=>x.ResumeDetails.Select(y=>y.DisplayStyle))
.First(x=>x.CustomerDetailsID == customerId);
My pocos are here:
[Table("CustomerDetails")]
public class Data_CustomerDetail
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Data_CustomerDetail()
{
ResumeDetails = new HashSet<Data_ResumeDetail>();
}
[Key]
public int CustomerDetailsID { get; set; }
[StringLength(500)]
public string FirstName { get; set; }
[StringLength(500)]
public string LastName { get; set; }
[StringLength(50)]
public string phoneNumber { get; set; }
[StringLength(50)]
public string Zipcode { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Data_ResumeDetail> ResumeDetails { get; set; }
}
public class Data_DisplayStyle
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Data_DisplayStyle()
{
ResumeDetails = new HashSet<Data_ResumeDetail>();
}
public int DisplayStyleID { get; set; }
[StringLength(500)]
public string Name { get; set; }
[StringLength(500)]
public string Description { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Data_ResumeDetail> ResumeDetails { get; set; }
}
[Table("ResumeDetails")]
public class Data_ResumeDetail
{
[Key]
public int ResumeDetailsId { get; set; }
[Column("CAREER OBJECTIVE")]
[StringLength(4000)]
public string CAREER_OBJECTIVE { get; set; }
[Column("HONORS AND REWARDS")]
[StringLength(4000)]
public string HONORS_AND_REWARDS { get; set; }
[Column("PROFESSIONAL RESPONSIBILITIES")]
[StringLength(4000)]
public string PROFESSIONAL_RESPONSIBILITIES { get; set; }
[Column("RELATED EXPERIENCE")]
[StringLength(4000)]
public string RELATED_EXPERIENCE { get; set; }
public int? CustomerDetailsID { get; set; }
public int? DisplayStyleId { get; set; }
public virtual Data_CustomerDetail CustomerDetail { get; set; }
public virtual Data_DisplayStyle DisplayStyle { get; set; }
}
Could someone please help me in resolving this...
I just want CustomerDetails and ResumeDetails and displaystyle table once... not multiple times..
This is increasing my object weight
When doing a foreign key relationship, you probably need to specify the foreign key(s)
Example:
modelBuilder
.Entity<Data_CustomerDetail>()
.HasMany(x => x.ResumeDetails)
.WithRequired(e => e.CustomerDetail)
.HasForeignKey(e => e.CustomerDetailsID)
.WillCascadeOnDelete(false);
modelBuilder
.Entity<Data_DisplayStyle>()
.HasMany(x => x.ResumeDetails)
.WithRequired(e => e.DisplayStyle)
.HasForeignKey(e => e.DisplayStyleId)
.WillCascadeOnDelete(false);