简体   繁体   English

具有现有数据库和具有多个源的类与手动存储过程的实体框架

[英]Entity Framework with existing database and classes with multiple sources vs manual stored procedures

New to Entity Framework and ORM, however possibly have a unique circumstance where we are thinking of somewhat refactoring how our application works.实体框架和 ORM 的新手,但是可能有一个独特的情况,我们正在考虑重构我们的应用程序的工作方式。

Right now we are using an in-memory distributed cache architecture, basically as an in-memory database in a fairly inefficient and error prone manner, whereby synchronization with persistent data, and even objects within the cache are not consistent.现在我们正在使用内存分布式缓存架构,基本上作为内存数据库以相当低效和容易出错的方式,与持久数据的同步,甚至缓存中的对象都不一致。

The thought is to somewhat go back to the core and either integrate some form of ORM like Entity Framework or to manually create stored procedures within SQL to bring in the data needed to create a complex class.我们的想法是在某种程度上回到核心,要么集成某种形式的 ORM,如实体框架,要么在 SQL 中手动创建存储过程,以引入创建复杂类所需的数据。

As an example, let's say we have a class of SomeDashboard that will have many properties that are set based on the Dashboard requested (stored in SQL), but then many lists of objects that are related to the Dashboard , such as Products or Reviews , etc. One could write a stored procedure that would utilize a single DB request that would pull back multiple result sets to create all of those lists and object values.举个例子,假设我们有一个SomeDashboard类,它有许多基于请求的Dashboard设置的属性(存储在 SQL 中),但是有许多与Dashboard相关的对象列表,例如ProductsReviews ,等等。人们可以编写一个存储过程,该过程将利用单个 DB 请求,该请求将拉回多个结果集以创建所有这些列表和对象值。

Would it be better to create the stored procedure to do that, or create multiple stored procedures to get the data in pieces (meaning more SQL calls), or to piggy-back off of Entity Framework to piece-mill all of the objects together?是创建存储过程来实现这一点,还是创建多个存储过程来分块获取数据(意味着更多的 SQL 调用),或者借助实体框架将所有对象拼凑在一起会更好吗?

Something that's going to be volatile, causing this to need to be rebuilt quite often;一些不稳定的东西,导致它需要经常重建; worried about scaling of the database with so many connections and so many requests per each time we build the object.担心每次我们构建对象时都会有如此多的连接和如此多的请求来扩展数据库。

Perhaps this makes enough sense to give some form of direction;也许这足以给出某种形式的方向; I know it's vague, at best.我知道这充其量是模糊的。

The other part of the question related to Entity Framework, would be -- how hard is it to map everything to existing databases and classes?与实体框架相关的问题的另一部分是——将所有内容映射到现有数据库和类有多难?

From a high level... feeling like the integration of the in-memory distributed caching was not thought out very well and done in such a way as to "preemptively optimize" that it's causing more issues than resolving;从高层次上看……感觉内存中分布式缓存的集成没有经过深思熟虑,并且以“抢先优化”的方式完成,导致问题多于解决; so going back to the roots and using SQL heavily, and then integrating caching selectively where it could be needed, and when performance with SQL becomes a problem seems like the best idea.所以回到根源并大量使用 SQL,然后在可能需要的地方有选择地集成缓存,当 SQL 的性能成为问题时,这似乎是最好的主意。

About the first part of your question, you should use eager loading on Entity Framework and let it query the data for you.关于问题的第一部分,您应该在实体框架上使用预先加载并让它为您查询数据。 This is the prupose of using an OR/M: you focus on the application code while OR/M does the raw part of reading and writing data to a SQL data source.这是使用 OR/M 的目的:您专注于应用程序代码,而 OR/M 执行读取和写入数据到 SQL 数据源的原始部分。

Check this MSDN article: Loading Related Entities .查看这篇 MSDN 文章:加载相关实体

About...关于...

The other part of the question related to Entity Framework, would be -- how hard is it to map everything to existing databases and classes与实体框架相关的问题的另一部分是——将所有内容映射到现有数据库和类有多难

This has no definitive answer.这没有确定的答案。 It might depend on your database design.这可能取决于您的数据库设计。 If your database was built with good relational design practices, usually an OR/M will be easier to configure against that database.如果您的数据库是使用良好的关系设计实践构建的,那么针对该数据库配置 OR/M 通常会更容易。

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

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