如何创建模型容器对象

发布于 2024-12-03 14:37:09 字数 1756 浏览 0 评论 0原文

我问了这个问题不久前,但没有人能够解决这个问题。所以我做了一些更多的测试,并确定问题存在于我的代码中。所以我的问题是,我做错了什么?

所以我创建了模型容器:

Private mdbContext As PFModelContainer
Private mdbTransactions As Object

在我这样做之前:

Private mdbContext As New PFModelContainer
Private mdbTransactions As mdbContext.Transactions

认为我可能做错了什么,我将其更改为第一种方式,然后我这样做:

Public Sub New()
  mdbContext = New PFModelContainer
  mdbTransactions = mdbContext.Transactions
End Sub

一旦我点击 mdbContext = New PFModelContainer 它需要我转到 PFModel.Designer.vb,它执行以下步骤:

Public Sub New()
  MyBase.New("name=PFModelContainer", "PFModelContainer")

此时它终止代码的执行。我在这里做错了什么吗?

这是它在“立即”窗口上给我的错误:

发生了“System.ArgumentException”类型的第一次机会异常 在System.Data.Entity.dll中

我可以采取什么措施来消除此错误?我尝试删除该项目并使用旧的 .edmx 模型重新创建它,该模型是我在 Mozy 运行时下载的。在我更改 .edmx 模型并更新它后,它停止工作(据我所知)。也许我在另一个项目中也做了其他事情,但我不记得任何事情。

这是 app.config 中的内容:

<connectionStrings>
    <add name="PFModelContainer" connectionString="metadata=res://*/PFModel.csdl|res://*/PFModel.ssdl|res://*/PFModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=|DataDirectory|\bin\Debug\MyDatabase#1.sdf&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

我应该在某处引用 System.Data.EntityClientSystem.Data.SqlServerCe.3.5 吗?

EDMX 属性实体容器名称PFModelContainer命名空间PFModel

I asked this question a while back but no one was a able to tackle it. So I did some more testing and determined it is in my code that the problem exists. So my question is, what am I doing wrong?

So I create the model container:

Private mdbContext As PFModelContainer
Private mdbTransactions As Object

Before I did it this way:

Private mdbContext As New PFModelContainer
Private mdbTransactions As mdbContext.Transactions

Thinking maybe I was doing something wrong I changed it over to the first way, then I do:

Public Sub New()
  mdbContext = New PFModelContainer
  mdbTransactions = mdbContext.Transactions
End Sub

Once I hit mdbContext = New PFModelContainer it takes me over to the PFModel.Designer.vb Where it steps through the following:

Public Sub New()
  MyBase.New("name=PFModelContainer", "PFModelContainer")

At which point it terminates execution of the code. Am I doing something wrong here?

This is the error it gives me on the Immediate window:

A first chance exception of type 'System.ArgumentException' occurred
in System.Data.Entity.dll

Is there something I can do to make this error go away? I tried deleting the project and recreating it with my old .edmx model that I downloaded from Mozy from when it used to work. It stopped working (as far as I can tell) after I changed the .edmx model and updated it. Maybe I did something else in the other project too, but I'm not recalling anything.

This is what is in the app.config:

<connectionStrings>
    <add name="PFModelContainer" connectionString="metadata=res://*/PFModel.csdl|res://*/PFModel.ssdl|res://*/PFModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\bin\Debug\MyDatabase#1.sdf"" providerName="System.Data.EntityClient" />
  </connectionStrings>

Should I be referencing System.Data.EntityClient and System.Data.SqlServerCe.3.5 somewhere?

The EDMX property Entity Container Name is PFModelContainer and the Namespace is PFModel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

北座城市 2024-12-10 14:37:09

好的,事实证明我需要通过右键单击 edmx 模型并按来更新 tt 模型

添加代码生成项

然后

ADO.NET DbContext 生成器

我想我以前做过,但我不记得做过。

OK, it turns out that I need to update the tt model by right clicking in the edmx model and pressing

Add Code Generation Item

Then

ADO.NET DbContext Generator

I suppose I did it before but I don't remember doing it.

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