user1173169
user1173169

Reputation:

Using of Entity Framework T4 POCO

I have been using Linq-to-SQL for a while to get access to my database. But I have recently been told this way of doing was not the best one since it allows to mix the data access & business logic layers.

I heard that Entity Framework T4 POCO was a solution but I cannot find complete information about it. Does anyone have more details to share with me ?

Thanks in advance

Upvotes: 4

Views: 4055

Answers (3)

algreat
algreat

Reputation: 9002

See that: Entity Framework - Generating Classes

There is a tutorial how to generate POCO Classes by existing database.

Upvotes: 0

Rick Hoving
Rick Hoving

Reputation: 3575

What a POCO (Plain Old CLR Object) does it that it allows you to create your own representation class of your database. Entity Framework then converts your database (through a configuration (hint use an edmx file)) to the by you created POCO classes.

Example:

Table User:

id | fName | lName | otherField

You can represent this in your C# with a POCO to a user object with the following properties:

int id, string fName, string lName, var otherField.

Then you can, in the getters and setters of these properties, insert your business logic.

NOTE: I'd recommend using just the Entity Framework icm with an edmx file. And put your business logic somewhere else. When creating a web service I always like the following order of classes :

  • A class that receives the calls and calls the right functions of the next class
  • This class then converts the given params in the call into a format that the rest of the application understands and calls the right functions of another class.
  • This class then checks the business logic in the params and calls another class to do something with the database.
  • This class then handles the database connection and stuff (with use of the Entity Framework) Note again: you can also use POCO's in this last step ;)

Upvotes: 1

I find this site gives a great example on how to use EF4 with POCO classes.

http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

This describes the 'code first' approach for Entity Framework 4

Upvotes: 0

Related Questions