EF6 using custom property in a linq query

asp.net-mvc c# entity-framework-6 linq

Question

One of my classes has the following characteristic:

[NotMapped]
public string Key
{
    get
    {
        return string.Format("{0}_{1}", Process.Name, LocalSequenceNumber);
    }
}

The local sequence number is a calculated integer supported by a concurrent dictionary-style cache.

I want to utilize the aforementioned Key property in a LINQ query, but I receive the following exception:

The specified type member 'Key' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

Although I know why I'm receiving this problem, I'm not sure how to fix it. I don't want to give up the excellent encapsulation that the Key property now gives my class. Any ideas for libraries or straightforward techniques to get around this?

The query that is producing the exception is as follows:

db.Cars.SingleOrDefault(c => c.Id == id && c.Key == key);
1
1
10/15/2018 5:53:36 AM

Popular Answer

ZZZ_tmp
2
10/15/2018 4:48:10 AM


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