简体   繁体   English

用于建模类的Dapper和Entity框架

[英]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. 我想开始使用Dapper,因为我认为与存储过程一起使用要比用实体框架映射每个存储过程来替换CRUD操作要容易得多。

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? 我想知道如何使用dapper创建POCO类,如果不可能,是否可以使用实体框架从数据库中创建模型,然后使用通过dapper创建的类?

Thanks! 谢谢!

There are a number of projects where I have used dapper alongside Entity Framework / nHibernate. 在许多项目中,我已将dapper与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. 为Dapper创建的POCO类与代码优先实体框架使用的域实体之间存在区别,您应该同时创建两者。

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. 遵循单一职责实践,您使用的POCO类应仅包含与存储过程进行交互的属性。

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. 如果您没有使用Entity Framework进行数据访问,而是想用Dapper和存储过程完全替换它,那么您将无法实现ORM的任何好处,而应该简单地手工制作其使用的架构和POCO类。

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. 考虑到创建自己的类的开销(可以更好地针对应用程序层进行定制),您可以从模式中生成POCOS,并且可以使用此工具来实现此目的,我想这没有任何好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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