简体   繁体   English

存储库模式,EF与存储过程

[英]Repository pattern, EF with stored procedures

We are pretty new to Entity Framework and the repository pattern, however trying to implement this into our system. 我们对Entity Framework和存储库模式都很陌生,但是尝试将其实现到我们的系统中。

We have a domain model (logical model) built which our system will work with, which is fine. 我们有一个我们的系统可以使用的域模型(逻辑模型),这很好。 The issue is we are struggling to understand how we map the returned data from a stored procedure to this domain model. 问题是我们正在努力理解如何将返回的数据从存储过程映射到此域模型。

The returned data from the stored procedure doesn't map to the entity model. 存储过程返回的数据不会映射到实体模型。

The only way I can think of doing this is purely by just executing the data reader, looping through the datareader, and assign each item directly, which seems dated... 我能想到这样做的唯一方法就是纯粹通过执行数据读取器,循环遍历datareader,并直接分配每个项目,这似乎过时了......

From a google search "DataMapping" seems to appear, however, cannot see any examples of how to implement this from a stored procedure to a domain model, only stored procedure to entity model. 然而,从谷歌搜索“DataMapping”似乎出现,无法看到任何如何从存储过程到域模型实现这一点的示例,只有存储过程到实体模型。

Let me ask a question. 我来问一个问题。

If you had decided to use plain ADO.NET to do the mapping, would you have been done by now? 如果你决定使用普通的ADO.NET进行映射,那么你现在已经完成了吗? Had everyone in the team understood to 100% what the code did? 如果团队中的每个人都理解代码的作用是100%吗?

Sometimes we just seem to try to apply new technology without really understanding why and what benefit it gives us. 有时我们似乎只是尝试应用新技术而没有真正理解为什么以及它给我们带来了什么好处。 What advantage have you seen with Entity Framework? 您在Entity Framework中看到了什么优势? What kind of time saving do you see in version 1 contra version 5 of your application? 您在应用程序的第1版对比版本5中看到了什么样的节省时间? What happens if the ORM fails? 如果ORM失败会怎么样? Will everyone in your team know why it fails? 团队中的每个人都会知道失败的原因吗?

If you are just using stored procedures it might be better to keep it simple (ADO.NET) or using a more lightweight mapper like Dapper or Massive . 如果您只是使用存储过程,最好保持简单(ADO.NET)或使用更轻量级的映射器,如DapperMassive

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

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