c# - Enum defined as IsOptional cannot be queried for null values -


i have defined enum property on entity via fluent api isoptional. database reflects isoptional shows nullable type. when attempt query entity property null values following error:

the 'usertype' property on 'group' not set 'null' value.  must set property non-null value of type 'usertype'. 

the query follows:

var groups = (from g in db.groups               let reqs = r in db.requests                r.id == requestid gg in r.groups select gg.id                                                 g.contentarea.id == db.requests.firstordefault(o => o.id == requestid).contentarea.id               !reqs.contains(g.id)               (g.usertype == db.requests.firstordefault(r => r.id == requestid).user.usertype || g.usertype == (usertype?)null)               select g).tolist(); 

and part breaks after or statement

g.usertype == (usertype?)null 

i've tried compare g.usertype null, set instance of usertype? nulltype = null , compared nothing seems work. seems shortcoming of ef. suggestions?

edit: included entire query requested.

the problem not in structure of statement, it's in entities ef tries materialize. group has property usertype that's not nullable. in database nullable , of returned records have null values it.

so either have make property nullable:

usertype? usertype { get; set; } 

or make sure statement doesn't return null values.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -