架构辅助:WCF可以与Entity Framework和MVC 2一起使用吗? [英] Architecture assistance: Can WCF be used with Entity Framework and MVC 2?

查看:55
本文介绍了架构辅助:WCF可以与Entity Framework和MVC 2一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ASP.NET MVC 2(Nerddinner等)进行了一些研究,并且非常希望使用这种架构来帮助确保新系统可测试性的可靠性。 在演练中,它使用Entity Framework作为模型和数据访问部分。 
使用Linq检索对象等非常好。真的很干净。真的分开了。 真的可以测试。但我有几个问题我希望你可以帮助我:


1. 我真的想使用存储过程,因为我想阻止访问基表并将EXECUTE权限授予应用程序角色。 此外,我觉得它更容易索引和调整数据库上的SQL。  可存储
程序是否可与Entity Framework一起有效使用? 看起来我无法在演练中执行简洁的LINQ查询,这些查询似乎能够通过任何字段进行查询,然后使用".Include(""自动获取并填充
子对象。 


2. 我可以在实体框架中使用WCF服务吗?这导致与#1相同的问题。我不清楚EF将如何互动使用该服务获取数据或如何完成。 创建我的WCF服务时是否使用EF?  
我想一旦弄清楚我可以使用存储库模式并只使用我的MVC 2控制器中的界面。  我的目标是我的网络应用程序可以使用这些服务,然后当我完成后,我可以为其他消费者准备好服务。


3.我猜这个架构我不能再使用Windows身份验证了。在之前的应用程序中,我使用Windows身份验证进入SQL Server数据库。但是为了防止他们直接登录数据库通过SQL Server Management
Studio,应用程序受SQL Server应用程序角色保护。 因此,连接在连接时传递了角色的密码,并将该用户添加到* that * connection的上下文中的应用程序角色。 然后,应用程序
角色拥有所有执行和选择权限。 这样做授予我从数据库角度进行真正合理审计的能力。但是,当我无法控制连接以告知EF时,它似乎不可能("嘿,加入
应用程序角色首先,执行您的执行,然后在关闭连接之前彻底保留应用程序角色。") 所以我想它会回到没有app角色的数据库服务ID?  


到目前为止,我已经在MVC 2上销售然后应用ViewModel和Repository模式,但是我我真的不清楚如何构建数据访问部分。 


如果您有任何个人输入/体验,演练或与#1和#2相关的链接,我会很感激它。

解决方案

1。查看第9频道的Wriju Ghosh的屏幕演员,他详细解释了它是如何工作的。


http://channel9.msdn.com/Blogs/wriju/Using-Stored-Procedure-in-ADONET-Entity-Framework-40


2。我只在服务器端使用EF,因此在数据访问层和业务层中。 WCF只是一个通信框架,通常位于应用程序和表示层之间(在服务层中或由演示文稿
和业务层直接使用)。因此,如果您希望通过服务公开功能,则应将实体框架包含在服务本身内。甚至来自EF的实体也无法直接通过WCF公开。


但是有一个替代方案,就是使用RIA框架。


3。您可以将Windows身份验证与实体框架一起使用,因为您可以通过模拟应用程序和WCF服务来模拟应用程序的每个部分,凭据(令牌)将传递到应用程序层,如果您配置
要使用集成安全性的连接字符串,模拟线程将使用用户的凭据查询数据库。之后,您只需要将具有相应角色的数据库层保护到适当的Active Directory组,并将
用户添加到Active Directory中的这些组。


您还可以模拟Web应用程序,但集成安全性仅与Internet Explorer兼容(无提示)。


查看  http://msdn.microsoft.com/en-us/library/ff647396.aspx


希望这个帮助。


I have studied a bit on ASP.NET MVC 2 (Nerddinner, etc.) and would really like to use this architecture to help ensure the reliability through testability of a new system.  In the walkthroughs, it uses Entity Framework as the Model and data access piece.  It was really nice using Linq to retrieve objects and such. Really clean. Really separated.  Really testable. But I had a few questions I was hoping you could help me with:

1.  I really want to use Stored Procedures because I want to prevent access to the base tables and grant EXECUTE authority to an application role.  Also I feel it will be easier to index and tune the SQL on the database.   Can Stored Procedures be used effectively with Entity Framework?  It seems like I wouldn't be able to do the neat LINQ queries that are in the walkthroughs that seem to be able to query by any field and then use the ".Include(" to automatically get and populate child objects. 

2.  Can I use WCF services with Entity Framework?  This leads to the same questions as #1.  I am unclear how EF would interact with the service to get the data or how that would be done.  Do I use EF when creating my WCF service?   I figure once this is figured out I can use the Repository pattern and just use the interface in my MVC 2 controllers.   My goal is that my web app can use the services and then when I'm done I have a services ready for other consumers.

3.  I guess with this architecture I can no longer use Windows authentication.  In the previous application, I used Windows Authenication into the SQL Server DB.  But to prevent them from directly logging into the DB via SQL Server Management Studio, the application was secured with SQL Server Application Roles.  So the connection passed a password for the role upon connecting and added that user to the application role within the context of *that* connection.  The application role then had all of the Execute and Select permissions.  Doing this granted me the ability of really sound auditing from a database perspective. But it doesn't seem possible when I can't control the connection in order to tell EF ("Hey, join the application role first, do your execution, then leave the application role cleanly before closing the connection.")  So I guess it would be back to the database service ID without app roles?  

So far I'm sold on the MVC 2 then applying ViewModel and Repository patterns, but I am really unclear how to architect the data access piece. 

If you have any personal input/experience, walkthroughs, or links that are relevant to #1 and #2, I woud appreciate it.

解决方案

1. Check out the screen cast of Wriju Ghosh on Channel 9, he explain in detail how it's working.

http://channel9.msdn.com/Blogs/wriju/Using-Stored-Procedure-in-ADONET-Entity-Framework-40

2. I would use EF only on the server side, so in the Data Access Layer and in the Business Layer. WCF is only a communication framework, that is usually between the application and the presentation layer (in a service layer or used directly by the presentation and business layer). So if you want to expose functionality thru a service, Entity Framework should be wrapped inside the service itself. Even the entities from EF could not be exposed directly thru WCF.

But there is an alternative out there, that is to use the RIA Framework.

3. You can use Windows Authentication with the entity framework, because you can impersonate each part of you application, by impersonating the application and the WCF service, the credential (token) will be passed to the application layer, and if you configure the connection string to use integrated security the the impersonated thread will query the database with the user's credential. After that, you only have to secure the database layer with the appropriate role to the appropriate Active Directory Group and add the users to those groups in Active Directory.

You can also impersonate Web Application, but the integrated security is only compatible (without prompt) with Internet Explorer.

Take a look at http://msdn.microsoft.com/en-us/library/ff647396.aspx.

Hope this help.


这篇关于架构辅助:WCF可以与Entity Framework和MVC 2一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆