POCO,Code first,model first and database first discussion

POCO is a stand for plain old CLR object. This Class where we have control over its base type and implemented interfaces so it doesn’t have to use any API specific features – that works same in whole EF. Code first is still EF and it uses internally same infrastructure like EDMX so there is no difference. Difference is how these classes are mapped to the database.

Database first uses EDMX file for describing whereas code first use for mapping in the code.

Pure code first doesn’t support for feature like database views or stored procedure.

Code first also mostly uses DBcontext API.

Untitled

Database first and model first has no real differences. Generated code is the same and we  can combine this approaches. For example, we can create database using designer, than we can alter database using sql script and update your model.

When we use code first we can’t alter model without recreation database and losing all data. this limitation is very strict and does not allow to use code first in production. But for now it is not truly usable.

Second minor disadvantage of code first is that model builder requires privileges on master database. This doesn’t affect if we use SQL Server Compact database or if control database server.

Advantage of code first is very clean and simple code. We have full control of this code and can easily modify and use it as view model.

It is recommended to use code first approach when you creating simple standalone application without versioning and using modeldatabase first in projects that requires modification in production.

 

 

Leave a Reply