LINQ to Entities中仅支持无参数构造函数和初始值设定项

时间:2013-04-22 12:18:15

标签: vb.net linq entity-framework

帮助我理解为什么这不起作用:

Dim i = (From f In EfUtil.Db.EMAILADDRESSHISTORY _
                Where f.EMAILADDRESS.CUSTOMERCONTACTPERSON.CUSTOMERguid = New Guid(Request.QueryString("customer")) _
                Select New With {.guid = f.ACTIONguid, .name = f.ACTIONname}).ToList

我收到以下错误

  

LINQ中仅支持无参数构造函数和初始值设定项   实体。

Altough我找到了许多这种结构的例子。我错过了什么?

1 个答案:

答案 0 :(得分:2)

您最常发现的示例是LINQ to Objects示例,而不是LINQ to Entities。

您可以通过事先声明GUID来解决此问题:

Dim customerGuid as Guid = New Guid(Request.QueryString("customer"))
Dim i = (From f In EfUtil.Db.EMAILADDRESSHISTORY _
         Where f.EMAILADDRESS.CUSTOMERCONTACTPERSON.CUSTOMERguid = customerGuid _
         Select New With {.guid = f.ACTIONguid, .name = f.ACTIONname}).ToList

要明确:此处的问题不是您的Select。问题是New Guid(...)条件中的Where