开发者

Custom property error in linq to entities

I am using EF4 and I am getting an error with my custom property. I have 2 properties in my Application class, namely Initials and Surname. It is a partial class. I created a custom property in my Application class called Owner, and it looks like this:

public partial class Application
{
   public string Owner
   {
      get
      {
         return Initials + " " + Surname;
      }
   }
}

When I add it to my grid like this:

m => m.Owner

Then I get the following error:

The specified 开发者_如何学Pythontype member 'Owner' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

How do I fix this?

Thanks Brendan


I think you should show more code because at the moment description of your problem is not complete. Anyway you can't use Owner property in any Linq query working with IQueryable (Linq to entities). Custom properties can never appear in Linq to entities query because such query is mapped to SQL where the property doesn't exist. You first have to select data with Linq to entities, call ToList or AsEnumerable and than select properties including Owner in Linq to objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜