views:

125

answers:

1

Hi,

I am working with Entity Framework 4.0 (VS 2010 Beta 2, NOT RC). I can model the EDM and produce the required database. When I ask VS to generate the code for the model, it generates the expected .designer.cs file. When I look at the factory methods for each entity that the designer has generated, I've noticed that it doesn't include all of the properties of the entity.

Is it correct to say that the factory method only includes properties that cannot be null ? This appears to be the case, but I'm not entirely sure.

Thanks,

Scott

+3  A: 

That's exactly the case, all non-nullable properties are parameters for the factory method. All nullable properties are not

Sander Rijken
Thanks Sander. One more question - how do I construct entities with the non-nullable fields set ? Would I call the factory to construct an instance and then assign the values after ?
Scott Davies
Personally I don't use them, I just construct the objects from scratch. The reason for this, is that the 'identity' generated primary key is also a parameter for the function. I don't want to pass a parameter for the primary key when creating a new object.
Sander Rijken
Ok, so you let the generator produce the .designer.cs, which produces the factory method, but you create your own method to instantiate the entity, bypassing the factory ?
Scott Davies
I just use, `new MyObject { Name="Foo", SomethingElse="Bar" };`
Sander Rijken