In Entity Framework, a constant variable of type 'System.Object' could not be created.

asp.net c# entity-framework

Question

My table is titledUserTenders having a connection of many to oneaspnet_Membership table.
When I do something similar with EntityFramework 4.0, it gives problems.

var tenders = ctx.UserTenders
    .Where(tender => tender.HasAdminApproved.Equals(true))
    .ToList();

The mistake is

System.NotSupportedException
Unable to create a constant value of type 'System.Object'.
Only primitive types ('such as Int32, String, and Guid') are supported in this context.

The passage below is effective.

var tenders = ctx.UserTenders.ToList();

How could my code possibly be flawed? I feel as if I am completely missing something.

I want to filter all of the rows with thebit field HasAdminApproved as true

1
21
7/19/2011 7:48:38 PM

Accepted Answer

Try substituting

.Where(tender => tender.HasAdminApproved.Equals(true))

With:

.Where(tender => tender.HasAdminApproved == true)

Alternatively, as recommended by @Ladislav Mrnka before, if your field isbool?

.Where(tender => tender.HasAdminApproved)
34
7/19/2011 8:00:55 PM

Popular Answer

You already knew the right response, @Ladislav (.Where(tender => tender.HasAdminApproved) ), however you can question why you get this notice.

You're attempting to dialSystem.Boolean.Equals(Object obj) . You're thus boxing the constant.true . Additionally, L2E does not accept a construct of a non-primitive type suchSystem.Object Hence the mistake.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow