简体   繁体   中英

Dapper and Entity framework for modeling classes

I want to start using Dapper because I think it's easier to use with Stored procedures than to map every stored procedure with Entity Framework to replace CRUD operations in general.

I would like to know how can I create the POCO classes with dapper, and if it is not possible, could I create the model from the Database using Entity framework and then use the classes created with dapper?

Thanks!

There are a number of projects where I have used dapper alongside Entity Framework / nHibernate.

There is a distinction between the POCO classes created for Dapper and the domain entities used by code first Entity Framework and you should create both.

Stored procedures will work with a shaped view of the data and do not have the responsibility of representing the entire domain.

Following single responsiblity practises the POCO classes you use should only contain those properties used by the stored procedures to are interfacing with.

If you are not using Entity Framework for data access and want to replace it completely with Dapper and stored procedures then you are failing to realise any of the benefits of an ORM and should simply hand craft the schema and the POCO classes it uses.

You can generate POCOS from a schema and tools exist to do this, given the overhead of creating your own classes which can be better tailored to the application layer I woudl suggest there would be no benefit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM