有没有办法使用Tuple类,但提供其中的项目名称?
例如:
public Tuple<int, int, int int> GetOrderRelatedIds()
Run Code Online (Sandbox Code Playgroud)
返回OrderGroupId,OrderTypeId,OrderSubTypeId和OrderRequirementId的id.
让我的方法的用户知道哪个是哪个是很好的.(当你调用方法时,结果是result.Item1,result.Item2,result.Item3,result.Item4.不清楚哪一个是哪个.)
(我知道我可以创建一个类来保存所有这些ID,但是这些ID已经拥有了他们自己的类,并为这个方法的返回值创建一个类看起来很傻.)
如何使用EF4在Select中检索元组?
var productCount = (from product in context.products
select new Tuple<Product, int>(product, products.Orders.Count));
Run Code Online (Sandbox Code Playgroud)
要么
var productCount = (from product in context.products
select Tuple.Create(product, products.Orders.Count));
Run Code Online (Sandbox Code Playgroud)
实体框架说第一种情况不能使用空构造函数,而第二种情况则不能识别Tuple.Create方法.
我正在尝试使用Linq to SQL作为Lambda表达式在2列上进行内部联接。普通查询如下所示。
SELECT * FROM participants
LEFT OUTER JOIN prereg_participants ON prereg_participants.barcode = participants.barcode
AND participants.event_id = prereg_participants.event_id
WHERE (participants.event_id = 123)
Run Code Online (Sandbox Code Playgroud)
我成功地在左列上使用以下代码进行了联接。
var dnrs = context.participants.GroupJoin(
context.prereg_participants,
x => x.barcode,
y => y.barcode,
(x, y) => new { deelnr = x, vi = y })
.SelectMany(
x => x.vi.DefaultIfEmpty(),
(x, y) => new { deelnr = x, vi = y })
.Where(x => x.deelnr.deelnr.event_id == 123)
.ToList();
Run Code Online (Sandbox Code Playgroud)
问题在于,使用上述Lambda时,我得到了太多结果,因为它缺少AND participants.event_id = prereg_participants.event_id零件。但是,无论我怎么努力,我都没有得到正确数量的参与者。
我查看了以下现有问题,但是在编写正确的lambda时没有一个解决了我的问题。而且大多数解决方案都是lambda格式的nog或不是多列上的Left外部联接。