开发者

Question about Northwind DB example

When开发者_Python百科 messing with the Subsonic 3.0 Northwind stuff:

var product = Product.SingleOrDefault(x => x.ProductID == 1);

I found the following was possible, but not workable) using intellisense:

var product = Product.SingleOrDefault(x => x.OrderDetails == 1);

OrderDetails as a member of Product, is an IQueryable. I guess I'm new to LINQ, but I was wondering how to use this member? Everytime I try to get info out of this I get an error. Could someone give me an example of how to use the OrderDetails member of Product? And perhaps throw the results in a databind to a Gridview?

Look at the following code and tell me what I'm doing wrong:

 var products = from od in OrderDetail.All()
                   join p in Product.All() on od.ProductID equals p.ProductID
                   select od;

I get the following error:

Object of type 'System.Single' cannot be converted to type 'System.Decimal'.


The IQueriable members that are exposed by SubSonic are your Foreign Keys. You could use them in the following manner.

 Product.SingleOrDefault(x => x.ProductID == 1).OrderDetails.ToList()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜