嗨,我正在尝试将 EF 与代码优先工作流一起用于现有数据库,但出现错误:
{“值不能为空。参数名称:源”}
使用以下行时:
Dim ctx = New MVCTest1
Dim t = ctx.Companies.ToList()
我的 POCO 课程包括以下内容:
我有一个名为 MVCTest1 的标准 conn 字符串,它指向 SQL Server。我认为 EF 正在使用它,因为我可以在 dbContext 的连接字符串中看到它。conn 字符串是否需要采用特殊格式。我还注意到 onmodelcreated 没有被调用。我不确定这是否相关。对此非常新,所以我怀疑这很明显干杯,克里斯
Imports System.Data.Entity
Public Class Company
Public CompanyID As Integer
Public CompanyName As String
Public Overridable Property Contacts As ICollection(Of Contact)
End Class
Public Class Contact
Public ContactID As Integer
Public FirstName As String
Public LastName As String
Public Overridable Property Company As Company
End Class
Public Class MVCTest1
Inherits DbContext
Public Contacts As DbSet(Of Contact)
Public Companies As DbSet(Of Company)
Protected Overrides Sub OnModelCreating(ByVal modelBuilder As System.Data.Entity.DbModelBuilder)
---Not being called
End Sub
End Class