类似数据库-实体模型框架

发布于 2024-11-09 09:39:40 字数 910 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心舞飞扬 2024-11-16 09:39:40

如果您具有相同的结构,则无需创建两个模型。您只能创建一个模型并使用不同的实例通过不同的连接字符串连接到不同的数据库。

您的上下文可以将连接字符串作为构造函数中的参数,并且您可以在其中指定两个不同的连接字符串。

只需创建一个模型 MyModel,

MyModelEntities companyContext = 
    new MyModelEntities("company connection string");

MyModelEntities privateContext = 
    new MyModelEntities("private connection string");

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,

MyModelEntities companyContext = 
    new MyModelEntities("company connection string");

MyModelEntities privateContext = 
    new MyModelEntities("private connection string");
凉墨 2024-11-16 09:39:40

我正在寻找的实际答案似乎只能通过调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文