Hello I am a Entity Framework newb and I am trying to get the following code into a single query for a data relationship. The relationship is one to many.
The code that does not work:
var categories = db.DataModel.Categories
.Where(c => c.CategoryTypeID == getCategoryTypeID(selectedId));
int getCategoryTypeID(int selectedTypeId)
{
return db.DataModel.CategoryLinkTypes.Where(l => l.ID == selectedTypeId)
.FirstOrDefault().ToInt(0);
}
I hope you can see what I am trying to do. When I run this code I get this error:
LINQ to Entities does not recognize the method ‘Int32 getCategoryTypeID(Int32)’
method, and this method cannot be translated into a store expression.
Can someone show me the proper way to do this?
I am using EF 4 + and C#
You can try pulling your function out of the link query: