Russell
Russell

Reputation: 17737

ADO.net entity framework - Custom code

I am investigating some OR/M's and have been unable to find an answer to this question.

I am currently looking at Microsoft's ADO .net entity framework.

Can I override (or use partial classes) to insert custom code into the entities that are created from the database?

It appears that the entities are generated using Xml (not my favourite method of implementation), so I'm not sure if I can put custom code into the classes.

If it can't, can this be done using Linq to SQL?

I have seen T4, and I think it is promising, but at this stage the maintenance moves from entity classes to templates.

Upvotes: 1

Views: 734

Answers (1)

LukLed
LukLed

Reputation: 31882

Yes, you can create additional code to existing classes. EF classes are partial. I use it to add validation logic and implement common interfaces. If you want to use DataAnnotations, you have to use additional metadata classes.

To extend your class, just create new class:

public partial class YourEFClassName
{
     //Here you can pute code
}

Upvotes: 2

Related Questions