linq to sql 中的分组依据和连接表
我有以下 3 个类(映射到 sql 表)。
Places table:
Name(key)
Address
Capacity
Events table:
Name(key)
Date
Place
Orders table:
Id(key)
EventName
Qty
Places 和 Events 表通过 Places.Name = Events.Place 连接,而 Events 和 Orders 表: Events.Name = Orders.EventName 。 任务是给定一个事件,归还该事件剩余的门票。容量是一个地方可以容纳的数量,数量是某人订购的门票数量。因此需要在订单表中进行某种分组,然后从容量中减去总和。
I have the following 3 classes(mapped to sql tables).
Places table:
Name(key)
Address
Capacity
Events table:
Name(key)
Date
Place
Orders table:
Id(key)
EventName
Qty
The Places and Events tables are connected through Places.Name = Events.Place, while the Events and Orders tables: Events.Name = Orders.EventName .
The task is that given an event, return the tickets left for that event. Capacity is the number a place can hold and Qty is the number of tickets ordered by someone. So some sort of grouping in the Orders table is needed and then subtract the sum from capacity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西(下面的 C# 代码示例)?
抱歉,变量名称很奇怪,但事件是一个关键字:)
我没有使用Visual Studio,所以我希望语法是正确的。
如果事件有多个地点,最后两行将如下所示:
旁注
LINQ 101 是熟悉 LINQ 的好方法:http://msdn.microsoft.com /zh-cn/vcsharp/aa336746
Something like this (C# code sample below)?
Sorry for the weird variable names, but event is a keyword :)
I didn't use visual studio, so I hope that the syntax is correct.
If the Event has multiple places, the last two lines would look like this:
On a sidenote
LINQ 101 is a great way to get familiar with LINQ: http://msdn.microsoft.com/en-us/vcsharp/aa336746