JD Stuart
JD Stuart

Reputation: 557

Cannot query property named "group" on EF object

I have an EF entity object sysSettings class that has a few properties. group and name is among these properties.

quer in the code below is an IQueryable<sysSettings> object.

When trying to write the following query, I'm having difficulty with the second where clause.

var query = from setting in quer
    where (setting.name.Equals("Url") && setting.group.Equals("system"))
select setting;

It seems that when I have a property on an Entity object called group I cannot access that property from within the LINQ query.

I think this might be because group may be a reserved/contextual work/action in LINQ.

Changing the property name of the Entity is unfortunately not an option.

Upvotes: 2

Views: 164

Answers (2)

Laszlo Boke
Laszlo Boke

Reputation: 1329

What if you write in fluent syntax?

var query = quer.Where(e => e.name.Equals("Url") &&
                            e.group.Equals("system"));

Upvotes: 1

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236238

Add @ symbol to your property name (only for query, do not change settings class definition):

var query = from setting in quer
            where (setting.name.Equals("Url") && [email protected]("system"))
            select setting;

This symbol allows you to to use reserved word (which is group).

Upvotes: 4

Related Questions