Since the types of entities are different, your add operation will fall for sure.
You will need a mapper or (explicit/implicit) conversion operator between your entity types I think.
To make it clear, for the conversation solution, suppose you have Entity1
and Entity2
and both have properties, Property
, Property_1
, Property_2
and Property_3
. I assume that you have default code generation strategy (not POCO or sth). Then you can add partial Entity2 and Entity1 classes with implicit conversion operatior, for example:
public partial class Entity2
{
public static implicit operator Entity2(Entity1 entity1)
{
return new Entity2()
{
Property = entity1.Property,
Property_1 = entity1.Property_1,
Property_2 = entity1.Property_2,
Property_3 = entity1.Property_3
};
}
}
So you can now do:
using (var provider = new Model1Container12())
{
Entity1 entity1 = new Entity1();
provider.AddObject(provider.Entity2Set.Name, entity1);
// or
provider.AddToEntity2Set(entity1);
}
The conversion will be made implicitly as you define in the conversion operator definition.
I don't know if Entity Framework itself has a solution for this situation but conversion seems like a solution for me. Or you can also use AutoMapper kind of thing. I don't have detailed information on that.