Entity Framework 4.0 . Entity Creation -


we have 2 entities identical columns entity name different. can create 2 entity using first entity instance ?

we tried doing .addobject("entity2 name",entityoneinstance) failing.

please suggest whether possible or other approach.

thanks in advance

since types of entities different, add operation fall sure.

you need mapper or (explicit/implicit) conversion operator between entity types think.

to make clear, conversation solution, suppose have entity1 , entity2 , both have properties, property, property_1, property_2 , property_3. assume have default code generation strategy (not poco or sth). can add partial entity2 , entity1 classes implicit conversion operatior, 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 can do:

using (var provider = new model1container12()) {     entity1 entity1 = new entity1();     provider.addobject(provider.entity2set.name, entity1);     // or     provider.addtoentity2set(entity1); } 

the conversion made implicitly define in conversion operator definition.

i don't know if entity framework has solution situation conversion seems solution me. or can use automapper kind of thing. don't have detailed information on that.


Comments

Popular posts from this blog

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -

jtree - comparing two TreeNode (or DefaultMutableTreeNode) objects in Java Comparator -