I like Entity Framework (EF), I think it is a little too rigid sometimes and it would be very nice if there was a very straight forward way to get Plain Old CLR Objects (POCO) out of EF Entities. One can dream, can he not?! Going on a tangent, there are ways to get POCO out of EF Entities, but I haven’t gotten them to work yet, I have looked through many tutorials and wasted a full work day trying to find a way around it. That being said, beware if you plan on using EF with WCF, some of your more complicated EF Entities will not go over the pipe in WCF. The reason simply being that there are un-serializable properties in those Entities. Hence the need for POCO.

I would really have liked EF to just have very simplistic syntax for the most basic of operations, those being CRUD operations. Since that is not the case, I am going to just put it here on my blog because I don’t think I should have to ever look this stuff up again (I’ve done this too many times already).

I am going to use everyone’s favorite used to death example, yes you guessed it – the Product object.

Read Operations

Write Operations

Not terribly complicated once you have the code in front of you, but it isn’t obvious when starting from scratch. I am debating on making extension methods for all of this so it will simply read: context.Insert(), context.Update(), context.Delete() etc..

Leave a Reply

Your email address will not be published. Required fields are marked *