设计建议:实体框架对存储过程有用吗?
我是 .NET 新手,处于数据库前端应用程序设计过程的早期,正在寻求一些建议。
我不确定我是否明白......
数据库是非常强规范化的,但提供了大量存储过程来抽象逻辑模型(例如,选择存储过程从密切反映业务对象的多个表中返回一个数据集,插入/更新存储过程多个表等..)
我应该如何设计 DAL ? 我不确定实体框架在这种情况下有什么好处。 生成后,它反映了规范化的数据库模式,而不是它的抽象。 或者,如果我映射存储过程来生成它(这需要一些工作,因为存储过程中的 T-SQL 是动态的并且带有连接),我可以得到业务对象,但看不到它的好处:实体代表一个由于单个“抽象”表,而不是一组具有数据关系的实体,存储过程处理对多个表的调用。将生成的更改事件映射到存储过程似乎比直接调用存储过程需要更多工作。
我缺少什么?
谢谢,
迈克尔。
I am new to .NET and early in the design process of a front-end application for a database, and looking for some advice.
I am not sure I get it...
The DB is very strongly normalized, but provides lots of stored procedures to abstract the logical model (ex. Select sproc returns one data set from multiple tables closely reflecting the business object, Insert/Update sprocs to multiple tables, etc..)
How should I design the DAL ?
I'm not sure what the benefit of the Entity Framework is in this context.
When generated, it reflects the normalized DB schema rather than an abstraction of it.
Or if I map the sprocs to generate it (which requires some work since the T-SQL in the sprocs is dynamic and with joins), I get the business objects alright but can't see the benefit of it : the entities represent to a single 'abstract' table, and not a set of entities with Datarelations, the sprocs handles the calls to multiple tables. It seems more work to map the generated change events to the sprocs than to call the sprocs directly.
What am I missing ?
Thanks,
Michael.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 EF 来完成此操作,但设计器不会帮助您;它不知道如何从存储过程签名派生实体类型。您需要手动编写 EDMX。 CTP 4 代码优先可能更容易,但我从未尝试过。
You can do this with the EF, but the designer won't help you; it doesn't know how to derive an entity type from a stored proc signature. You would need to write the EDMX by hand. CTP 4 code-first may be easier, but I've never tried it.
经过一些研究,我认为我开始走上正确的道路。
以下文章非常有帮助:
实体框架建模:每个层次结构的表继承
另请参阅:实体框架建模:实体拆分
需要明确的是,我想要的是在 EF 模型中抽象 DB 架构。
(我不希望任何实体代表“无”,例如多对多关系)。
除了这些建模技术之外,我还使用视图来生成 EF 模型,并添加用于 CRUD 的存储过程。
正如我所说,我是一个初学者。如果我走错了路,请告诉我......
After some research, I think I'm starting to be on the right track.
The following articles were very helpful :
Entity Framework Modeling: Table Per Hierarchy Inheritance
see also : Entity Framework Modeling : Entity Splitting
To be clear, what I wanted was to abstract the DB schema in the EF model.
(I didn't want any entity representing 'nothing', like a many-to-many relationship).
Besides these modeling techniques, I used views to generate the EF model, and added sprocs for CRUD.
As I said, I am a beginner. Let me know if I am on a wrong track...