Why use byte[] instead of EntityKey ?

Why use byte[] instead of EntityKey ?

Old forum URL: forums.lhotka.net/forums/t/9151.aspx

lukky posted on Wednesday, June 30, 2010


In the sample code for the CSLA 3.8 core video series, in the Core380\Data\ObjectFactory\Library\TestObject.cs file, you add a PropertyInfo for the EF EntityKey, which, if I understand correctly, is useful in preventing a round-trip to the DB during updates.

My question is, why do you set that PropertyInfo to type "byte[]", which forces you to Serialize/Deserialize it, instead of just using System.Data.EntityKey ?


RockfordLhotka replied on Wednesday, June 30, 2010

If I use the EntityKey type, then all my code needs to reference EF, even client-side libraries and things that shouldn't have to have such a reference.

That couples my entire app to EF, which is (imo) a bad thing. I want only my DAL to be coupled to EF.

Additionally, it might be that EntityKey isn't serializable? I don't know for sure.

I am reasonably certain it won't serialize to Silverlight, where EF doesn't exist at all.

And that's probably the key - most of my work for a long time now has been Silverlight focused - so things that don't work or exist on Silverlight must be isolated very carefully so they are only used in very controlled parts of the code.

lukky replied on Wednesday, June 30, 2010

Makes tons of sense Big Smile


Copyright (c) Marimer LLC