LINQ for Entities only supports constructors and initializers without parameters

Help me understand why this is not 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 get the following error

LINQ supports only parameterless constructors and object initializers.

Although I find many examples where this design works. What am I missing?

+1
source share
1 answer

The most likely examples are LINQ to Objects, not LINQ to Entities.

You can get around this by declaring a 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

To be clear: the problem is not yours Select. The problem is New Guid(...)in Where.

+2
source

All Articles