Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 值不能为null。参数名称:source";实体框架代码优先_Entity Framework_Code First - Fatal编程技术网

Entity framework 值不能为null。参数名称:source";实体框架代码优先

Entity framework 值不能为null。参数名称:source";实体框架代码优先,entity-framework,code-first,Entity Framework,Code First,您好,我正在尝试对现有数据库使用EF和代码优先工作流,但我发现错误: {”值不能为空。 参数名称:源“} 使用以下行时: Dim ctx = New MVCTest1 Dim t = ctx.Companies.ToList() 我的POCO课程包括以下内容: 我有一个名为MVCTest1的标准conn字符串,它指向SQL Server。我认为EF正在使用它,因为我可以在dbContext的连接字符串中看到它。conn字符串是否需要采用特殊格式。我还注意到onmodelcrea

您好,我正在尝试对现有数据库使用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

问题在于
MVCTest1
中的
联系人
公司
是公共成员变量,而不是属性。因此,当您对它们进行寻址时,它们不会被初始化。

Ahhh。。。我的错误在于没有正确地转换复制的c#代码。谢谢