0

I'm a newbie at this and haven't quite got the grasp of DB first/Code first/POCO in EF. This is what I understand. Please let me know if this is accurate:

  1. In the DB first approach, the code is generated based upon an existing database. We can then choose to include tables/views/stored procedures. Tangentially, I see a lot of DB first approached where the database already has all the sprocs and the db. context only contains sprocs (function imports) but does not contain any table (db. set ) objects. In this case, why would you want to use EF? Why not just use ADO.Net with SQL Command?

  2. In the code first approach, the db. doesn't exist in the backend. the db. is generated using the POCO objects.

  3. POCO : Is this only used in code first?

D Stanley
  • 149,601
  • 11
  • 178
  • 240
user2250250
  • 865
  • 1
  • 7
  • 7

2 Answers2

0

why would you want to use EF? Why not just use ADO.Net with SQL Command

EF will populate the entity object for you automatically - with plain ADO.NET you have to populate the objects or use a different ORM framework.

In the code first approach, the database doesn't exist in the backend. the database is generated using the POCO objects.

Yes; it also keeps track of changes to the database between releases (although I still review the scripts since EF can do some strange things to update databases)

POCO : Is this only used in code first?

Not necessarily, there are T4 template frameworks out there that will generate POCO objects from existing database objects.

D Stanley
  • 149,601
  • 11
  • 178
  • 240
  • So does that mean in the code first approach, as and when we change the model classes, EF will take care of updating the DB? – user2250250 Dec 07 '13 at 03:28
  • @user2250250 EntityFramework will keep track of changes within the context when any entities are changed, however when ready, you have to call SaveChanges() from the dbContext. – TMan Dec 07 '13 at 15:08
0

Generally in code-first you create the models (or POCO's if you want to call it that) and the database is created based off your created model classes. In data-base first, like you said, you have an existing db that Entity framework takes and creates you POCO's (or your model classes) using a T4 Template. So no POCO's are not just for Code-first but actually is a term used more commonly in Data-base first. Hope this helps

Check this out as well: Code First vs. Database First Pros-Cons

Community
  • 1
  • 1
TMan
  • 4,044
  • 18
  • 63
  • 117
  • Thanks much for sharing the link. I've marked 'D Stanley' as the answer since he specifically relied to each one of my questions. – user2250250 Dec 08 '13 at 00:16