Answer the question
In order to leave comments, you need to log in
Entity Framework not saving related data?
Friends. I have a bathert from EF Core. I'm starting to get angry.
I have 2 entities
public class Realtor
{
public Realtor()
{
Guid = Guid.NewGuid();
Registration = DateTime.Now;
}
public int Id { get; set; }
public Guid Guid { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime Registration { get; set; }
public int SubdivId { get; set; }
public Subdiv Subdiv { get; set; }
}
public class Subdiv
{
public Subdiv()
{
Created = DateTime.Now;
}
public int Id { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
public List<Realtor> Realtors { get; set; }
}
modelBuilder.Entity<Realtor>(real => {
real.HasOne(r => r.Subdiv)
.WithMany(s => s.Realtors)
.HasForeignKey(r => r.SubdivId);
});
Answer the question
In order to leave comments, you need to log in
include() ?
More precisely, like this:
context.Subdivs.Include(i=>i.Realtor).First(s=>s.Id == id):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question