2
Using the . Net platform with the Entity Framework.
I am persisting an A_B class object 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 include A_B, automatically, the Entity Framework includes B and A, but I don’t 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 use only these lines:
context.Entry(A_B).State = EntityState.Modified;
or
context.Entry(A_B).State = EntityState.Added;
DbContext.SaveChanges();
vote against Would specificationToSave be the object of the car as well? If yes, you would have to take the wheel codes that are in the car, and set in the specificationToSave object. Has how to pass more details like which parameters of the objects, maybe?
– Joe Torres
Follows the classes public class A_B { private int Id; private string name; private A a; private B b b; } public class A { private int Id; private string name; } public class B { private int Id; private string name; }
– Leandro Duarte
It is not duplicate. I will answer.
– Leonel Sanches da Silva