Reputation: 998
Here i pass a parameter named PId. Which will be compare with another table's PId. But i getting error when the query is binding query to ToList().
ERROR: "The specified type member 'PId' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."
public IList<Models.MyModel> GetDaraByPId(Guid PId)
{
var query = this._Repository.GetIQueryable();
var list = query.Select(a => new Models.MyModel
{
MyModelId = a.Id,
MyModelName = a.Name
}).Where(f => f.PId == PId);
return list.ToList();
}
Upvotes: 2
Views: 634
Reputation: 21
I faced this problem too. Solution is that when you create a model constructor with condition by any parameter, the model must contain the Property which is for comparison. Here you miss 'PId' property of the model.
Upvotes: 0
Reputation: 217
You must have a value of 'PId' (PId=a.PId), Then you are able to use this in a condition (Where(f => f.PId == PId)).
public IList<Models.MyModel> GetDaraByPId(Guid PId)
{
var query = this._Repository.GetIQueryable();
var list = query.Select(a => new Models.MyModel
{
MyModelId = a.Id,
MyModelName = a.Name,
PId=a.PId
}).Where(f => f.PId == PId);
return list.ToList();
}
Upvotes: 2