开发者

How to Create Model Container Object

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 na开发者_Python百科me="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>

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜