LINQ to Entities中只支持无参数构造函数和初始值设置 [英] Only parameterless constructors and initializers are supported in LINQ to Entities
问题描述
帮我理解为什么这不工作:
Dim i =(From f In EfUtil.Db.EMAILADDRESSHISTORY _
其中f.EMAILADDRESS.CUSTOMERCONTACTPERSON.CUSTOMERguid = New Guid(Request.QueryString(customer))_
选择新建与{.guid = f.ACTIONguid,.name = f.ACTIONname})。 ToList
我收到以下错误
< blockquote>
LINQ
中仅支持无参数构造函数和初始值设置。
Altough I在这个建筑工程中发现很多例子。我缺少什么?
您发现最有可能的示例是LINQ to Objects示例,而不是LINQ to Entities。 p>
您可以通过事先声明GUID来解决此问题:
Dim customerGuid作为Guid = New Guid(Request.QueryString(customer))
Dim i =(From f In EfUtil.Db.EMAILADDRESSHISTORY _
其中f.EMAILADDRESS.CUSTOMERCONTACTPERSON.CUSTOMERguid = customerGuid _
选择新建{.guid = f.ACTIONguid,.name = f.ACTIONname})ToList
选择。问题是在 Where
条件中的 New Guid(...)
。
Help me understand why this isn't working:
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
I'm getting the following error
Only parameterless constructors and initializers are supported in LINQ to Entities.
Altough I'm finding a lot of examples where this construction works. What am I missing?
The examples you are finding most likely are LINQ to Objects examples and not LINQ to Entities.
You can work around this by declaring the GUID beforehand:
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
To be clear: The problem here is not your Select
. The problem is the New Guid(...)
in the Where
condition.
这篇关于LINQ to Entities中只支持无参数构造函数和初始值设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!