如何创建模型容器对象
我问了这个问题不久前,但没有人能够解决这个问题。所以我做了一些更多的测试,并确定问题存在于我的代码中。所以我的问题是,我做错了什么?
所以我创建了模型容器:
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="Data Source=|DataDirectory|\bin\Debug\MyDatabase#1.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
我应该在某处引用 System.Data.EntityClient
和 System.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,事实证明我需要通过右键单击 edmx 模型并按来更新 tt 模型
然后
我想我以前做过,但我不记得做过。
OK, it turns out that I need to update the tt model by right clicking in the edmx model and pressing
Then
I suppose I did it before but I don't remember doing it.