I've an Entity Framework model (v.1.0) that I'm trying to extends with a calculated property.
I've created the partial class to extend the entity object "Offer" in this way:
namespace MyModelNamespace
{
public partial class Offer
{
public bool MyProperty
{
get
{
// my stuffs the return true or false
}
}
}
}
It compiles without problem in my assembly, but at runtime, when I'm trying to do something like this:
_myEntities.OfferSet.FirstOrDefault(o=>o.MyProperty);
I retrieve this error:
The number of members in the conceptual type 'MyModelNamespace.Offer' does not match with the number of members on the object side type 'MyModelNamespace.Offer'. Make sure the number of members are the same.
...any suggestions???
Yes, you can do this. Use the LINQ translations library.
You can't push custom properties down to the database. You should have gotten something like
"The specified type member 'MyProperty' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."
The only valid way to do what you want is to get it into memory. And then filter.
_myEntities.OfferSet.ToList().FirstOrDefault(o=>o.MyProperty);
I am guessing there is probably a better way to accomplish whatever you are doing.
EDIT I agree Craig there is another way, assuming * it can be translated into a store expression. If you are mapping a property to some type of query, you will be able to search/push down the filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With