找到你要的答案

Q:Repositories calling existing stored procedures

Q:调用现有存储过程的存储库

Let's say I am developing a few ASP.NET MVC applications working with data in an existing database just over by stored procedures, no and never linq to entities or anything else. That database contains lots of schemas and all my web applications needs the different schemas as well.

Here is my point:

  • I have a x.Model project in my solution that contains my ADO.NET Entity Model to create return types for all of my stored procedures in my existing db.
  • I have x.Repository.y projects in my solution where y is the schema name in the database. These projects contains classes having functions to call the stored procedures from the appropriate schema by ADO.NET Entity Model's context. So I have to have reference of x.Model in these repository projects.
  • And I have ASP.NET MVC projects that uses the necessary injected repositories from x.Repository.y projects. I use some of these return types of stored procedures as models in my views, so I need a reference to x.Model project too. But in that case this reference gives all the context to client web applications. I don't want my whole or partial db entities is reachable in my web applications. I just want them to know about necessary repository classes.

Is it possible? How can I do that?

If I remove x.Model project and create the ADO.NET Entity Models containing just the appropriate schemas stored procedures in my x.Repository.y projects then the referencing web applications again knows about this schema's whole db entities.

Thanks in advance,

比方说,我开发了几个ASP.NET MVC应用程序与数据在现有数据库中的存储过程只在工作,没有没有实体LINQ或别的什么。该数据库包含大量的架构,并且我所有的web应用程序也需要不同的架构。

这是我的观点:

  • I have a x.Model project in my solution that contains my ADO.NET Entity Model to create return types for all of my stored procedures in my existing db.
  • I have x.Repository.y projects in my solution where y is the schema name in the database. These projects contains classes having functions to call the stored procedures from the appropriate schema by ADO.NET Entity Model's context. So I have to have reference of x.Model in these repository projects.
  • And I have ASP.NET MVC projects that uses the necessary injected repositories from x.Repository.y projects. I use some of these return types of stored procedures as models in my views, so I need a reference to x.Model project too. But in that case this reference gives all the context to client web applications. I don't want my whole or partial db entities is reachable in my web applications. I just want them to know about necessary repository classes.

这可能吗?我该怎么做?

如果我删除X模型项目和创建只包含适当的架构存储过程在我x.repository ADO.NET实体模型。Y项目引用的Web应用程序再知道这个模式的整个数据库的实体。

先谢谢了。

answer1: 回答1:

Maybe, better way to use Model First or Code First approach. So, you can describe pure (without references to DbContext and other Data classes) entities. Then, create mapping in x.Repository project. And referene your Model to ASP.NET MVC site. So, you will have only entities and repositories but mapping and DbContext will be hidden inside one reference (you can mark mapping classes as internal).

也许,更好的方式使用模型第一或Code First方法。所以,你可以描述纯(无DbContext和其他数据实体类的引用)。然后,在x中创建映射库项目。与参考模型ASP.NET MVC网站。所以,你只有实体和库但映射和DbContext将隐藏在一个参考(可以标记映射类的内部)。

asp.net-mvc  entity-framework  stored-procedures  architecture  repository-pattern