4

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

3 Answers3

1

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 ;)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rick Hoving
  • 3,585
  • 3
  • 29
  • 49
0

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

  • Code-first is **not** the same as using EF with POCO classes. You can use EF with a "traditional" database-first approach and an EDMX model and **still** have the T4 templates generate POCO classes for you.... – marc_s Apr 12 '12 at 09:02
  • @marc_s You are correct, I missed the T4 part in the question. – Matthijs van der Veer Apr 12 '12 at 10:16
0

See that: Entity Framework - Generating Classes

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

Community
  • 1
  • 1
algreat
  • 8,592
  • 5
  • 41
  • 54