I am working on Silverlight with C# using RIA Services - MVVM pattern . When I try to get records from Orders
and OrdersDetails
I get this error below:
'Notes' is not a member of
'Transient.collection[XXX.SilverLight.Web.Models.OrderDetails(Nullable=True,DefaultValue=)]'.
To extract a property of a collection element, use a subquery to iterate over the collection. Near simple identifier, line 6, column 58.
Here is my query:
public IQueryable<Order> AdvancedSearchOrder(string condition)
{
ObjectQuery<Order> myQuery = new ObjectQuery<Order>("Orders", DbContext.ObjectContext()).Include("OrderDetails");
if (condition != "")
{
myQuery = myQuery.Where(condition);
}
return myQuery;
}
In this case, I have
condition = "( (it.CustomerName like 'test') ) and ( (it.OrderDetails.Notes like 'testnote') )";
When I set it to
condition = "( (it.CustomerName like 'test') )";
then, it works great.
You are trying to use it.OrderDetails
as a set, which it likely isn't given that it has a plural name. I'm going to infer that your data model is each Order
has one or more OrderDetail
records. The list of OrderDetail
objects doesn't have a Notes
property. An individual OrderDetail
does. I'm not sure of the RIA syntax, but it should be something like this:
condition = "( (it.CustomerName like 'test') ) and (
(it.OrderDetails.Notes.Any(n => n.Contains('testnote')
)";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.