简体   繁体   English

使用Entity Framework在异地移动数据库

[英]Moving a database offsite while using Entity Framework

An app I'm currently working on uses Entity Framework 4 which connects to a database on the local network. 我正在使用的应用程序使用Entity Framework 4连接到本地网络上的数据库。 We now need this database to be hosted on a server at a different location. 我们现在需要将此数据库托管在不同位置的服务器上。 Obviously our client apps (Windows Forms) will still need to access the data. 显然,我们的客户端应用程序(Windows窗体)仍然需要访问数据。 Using a VPN would be the easiest, but that is not an option in this case. 使用VPN将是最简单的,但在这种情况下,这不是一个选项。 With that said, what are my options? 话虽如此,我的选择是什么? Is there a way I can expose the entity data model via web services that would require minimal rework of the client application? 有没有办法通过Web服务公开实体数据模型,这需要对客户端应用程序进行最少的返工?

Research into WCF Data Services: http://msdn.microsoft.com/en-us/library/cc668794.aspx 研究WCF数据服务: http//msdn.microsoft.com/en-us/library/cc668794.aspx

And have a quick read through this, to get an idea of how easy it is to setup wrapper service for EF. 并快速阅读本文,了解为EF设置包装器服务是多么容易。 http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx

In short; 简而言之; take a look at WCF Services, but make sure you don't expose IQueryable or IEnumerable instances via your service. 查看WCF服务,但请确保您不通过您的服务公开IQueryableIEnumerable实例。

The long rambling, possibly beer related version: 漫长的漫步,可能与啤酒相关的版本:

Without knowing the details of your application architecture it's hard to give a concrete answer. 在不了解应用程序架构的细节的情况下,很难给出具体的答案。

If you have built the application on a number of services classes inside your existing app you may be able to simply expose those services directly via some form of web service. 如果您已在现有应用程序内的许多服务类上构建应用程序,则可以通过某种形式的Web服务直接公开这些服务。 However, you must be careful if you have passed instances of IQueryable or IEnumerable across your service boundaries. 但是,如果已跨服务边界传递了IQueryableIEnumerable实例,则必须小心。 If you have you may find that porting to webservices causes very large amounts or data being passed over the network or you may see N+1 problems and the app may start to become very 'chatty'. 如果你有,你可能会发现移植到webservices导致非常大的数量或数据通过网络传递,或者你可能会看到N + 1问题,应用程序可能会开始变得非常'健谈'。

An alterative may be to give your users direct access to your database with a limited user. 一种替代方法可能是让用户使用有限的用户直接访问您的数据库。 This is always something I'm nervous of, especially if this is a public application. 这总是我很紧张的事情,特别是如果这是一个公共应用程序。 In this case you have to make sure that the sql user that you give them has the fewest and least permissions you can possibly get away with. 在这种情况下,您必须确保您提供给他们的sql用户具有您可能获得的最少和最少的权限。

You also need to be aware that moving off your local network will incur much larger latency when talking to your database. 您还需要注意,在与数据库通信时,离开本地网络会产生更大的延迟。 Depending on how your app is coded you may start to see the UI locking or hanging while the network round trip takes place. 根据应用程序的编码方式,您可能会在网络往返发生时开始看到UI锁定或挂起。

If you have coded your app well to begin with splitting out your db access into services, will at the very least be tricky (unless your app is very simple). 如果您已经很好地编写了应用程序以开始将数据库访问权限拆分为服务,那么至少会非常棘手(除非您的应用程序非常简单)。

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

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