简体   繁体   English

有关Northwind数据库示例的问题

[英]Question about Northwind DB example

When messing with the Subsonic 3.0 Northwind stuff: 当搞砸Subsonic 3.0 Northwind的东西时:

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

I found the following was possible, but not workable) using intellisense: 我发现使用intellisense可以进行以下操作,但不可行:

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

OrderDetails as a member of Product, is an IQueryable. 作为Product成员的OrderDetails是一个IQueryable。 I guess I'm new to LINQ, but I was wondering how to use this member? 我想我是LINQ的新手,但我想知道如何使用此成员? 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? 有人可以给我一个有关如何使用Product的OrderDetails成员的示例吗? And perhaps throw the results in a databind to a Gridview? 也许将结果放入数据绑定到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. SubSonic公开的IQueriable成员是您的外键。 You could use them in the following manner. 您可以按以下方式使用它们。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM