You're casting the result of the query to a list of
UserProductProperty
s, and that's not going to work because of two reasons;
1. The results of the query are of an anonymous type;
Selecting like this;
select new
{
PName = prop.ProductPropertyValue.ProductProperty.Name,
PValue = prop.ProductPropertyValue.Value
};
Will not create a
UserProductProperty
instance, but an instance of a new anonymous type.
2. The result might not be a
List
at all, all Linq is promising is that it is
IEnumerable
, but you can create a
List
from the
IEnumerable
.
Try changing you assignment to
model.ProductPropertyList
to this:
model.ProductPropertyList = (from prop in db.ProductSelectedPropertyValues
where prop.ProductId == ProductId
select
new UserProductProperty
{
PName = prop.ProductPropertyValue.ProductProperty.Name,
PValue = prop.ProductPropertyValue.Value
}).ToList();
The call to
ToList
will create a
List
and selecting
new UserProductProperty
will make sure you get the type you want.
Hope this helps,
Fredrik