类似数据库-实体模型框架
我的 DataAccess
项目中有两 (2) 个 SqlServerCe SP2 数据库。
为了便于说明,假设一个数据库是 Company.sdf,另一个数据库是 Private.sdf。两个数据库具有完全相同的结构:相同的表、相同的列 ID 等。
Company.sdf 数据库包含所有产品的最新信息,这些信息是从我们公司的服务器下载的,以便工程师和销售人员能够当网络连接不可用时访问信息。
Private.sdf 数据库包含工程师和销售人员为构建系统或估算成本而创建的任何项目或方案。
我首先为 Company.sdf 数据库创建一个名为 CompanyModel 的实体模型。经过一些困难,我终于得到了实体模型来连接它(Entity Framework Noobie)。
今天,我为 Private.sdf 数据库创建了第二个实体模型,名为 PrivateModel。执行此操作后,我收到多个错误,指出我的 DataAccess
项目的每个成员已包含其他数据库中类似项目的定义。
老鼠!
如何为类似数据库添加实体模型?
DataAccess
项目将成为我的 n 层方法中的 DAL。在此处搜索答案时,我在 3013146 中阅读了 RPM1984 的回复,了解模型应该如何不知道其连接到哪个数据库- 这是您的 DAL 存储库的工作,但我不确定如何最适合我的情况。
I have two (2) SqlServerCe SP2 databases in my DataAccess
project.
For the purposes of this explanation, let's say one database is Company.sdf and the other is Private.sdf. Both databases have the exact same structure: Same tables, same column IDs, etc.
The Company.sdf database contains the latest information on all products, as downloaded from our company's server to allow Engineers and Sales Personnel to access information when network connections are not available.
The Private.sdf database contains any projects or scenarios that Engineers and Sales Personnel have created to build a system or estimate a cost.
I started by creating an Entity Model for the Company.sdf database called CompanyModel. I finally got the Entity Model to connect to it after some difficulty (Entity Framework Noobie).
Today, I created my second Entity Model for the Private.sdf database called PrivateModel. As soon as I did this, I got multiple errors stating that each member of my DataAccess
project already contains a definition for a similar item in the other database.
R A T S !
How do I add Entity Models for similar databases?
The DataAccess
project is going to be my DAL in my n-tier approach. While searching here for answers, I read RPM1984's response in 3013146 about how a model should know nothing about which database its connecting to - this is the job of your DAL Repository, but I'm not sure how to best do this for my situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您具有相同的结构,则无需创建两个模型。您只能创建一个模型并使用不同的实例通过不同的连接字符串连接到不同的数据库。
您的上下文可以将连接字符串作为构造函数中的参数,并且您可以在其中指定两个不同的连接字符串。
只需创建一个模型 MyModel,
If you have same structure then you don't need to create two models. You can only create one model and use different instances to connect to different database using just different connection strings.
Your context can take connection string as parameter in constructor and there you can specify two different connection strings.
Just create one model, MyModel,
您需要实现存储库模式。以下是一些非常简单示例的链接。
http ://blogs.microsoft.co.il/blogs/gilf/archive/2010/01/20/using-repository-pattern-with-entity-framework.aspx
http ://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx
You need to implement the Repository pattern. Here are a few links to a very simple examples.
http://blogs.microsoft.co.il/blogs/gilf/archive/2010/01/20/using-repository-pattern-with-entity-framework.aspx
http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx
我正在寻找的实际答案似乎只能通过调用 EdmGen2 来解决。我会进一步向大家更新。
如果有人知道实际执行此操作的方法,请随意发表评论或添加答案。
与此同时,我陷入了教程模式。
更新:
CodeProject 上的 SteveQ56:
和
这些似乎为我指明了我想要走的方向,而不必依赖 EdmGen2。
The actual answer I'm looking for appears to be solved only by calling EdmGen2. I will update everyone further.
Feel free to comment or add answers if anyone knows of a way to actually do this.
In the mean time, I'm stuck in tutorial mode.
UPDATE:
I've been pointed to a couple of good references by SteveQ56 on CodeProject:
and
These seem to point me in the direction I want to go without having to fall back on EdmGen2.