Using the .Net platform with the Entity Framework.
I'm persisting an object of class A_B that relates to A and B as code below:
public class A_B
{
private int Id;
private string name;
private A a;
private B b;
}
public class A
{
private int Id;
private string name;
}
public class B
{
private int Id;
private string name;
}
The problem is that every time I add A_B, the Entity Framework automatically includes B and A, but I do not want to include B and A because they already exist in the database. I am including only the relationship between these objects.
To save I only use these lines:
context.Entry(A_B).State = EntityState.Modified;
or
context.Entry(A_B).State = EntityState.Added;
DbContext.SaveChanges();