Silverlight 在连接上使用 Entity to LINQ
我有以下代码,它可以工作并为我获取单个实体的数据。
LoadOperation<TimeForm> loadoperation = _cc.Load(_cc.GetTimeFormsQuery()
.Where(o => o.Start>= weekrange.startdate
&& o.End<= weekrange.enddate
&& o.USERID== "TEST"));
但是我有 3 个表连接到这个 TimeForm 表,在 sql 中我的查询如下所示:
SELECT T* FROM TimeForm
INNER JOIN CLIENT ON TimeForm.CODEID= CLIENT.CODEID
INNER JOIN RATE ON TimeForm.RATEID= RATE.RATEID
INNER JOIN TASK ON TimeForm.TASKID = TASK.TASKID
使用上面的语法怎么可能?我需要这些表中的一些值。
I have the following code which works and gets me the data for a single entity.
LoadOperation<TimeForm> loadoperation = _cc.Load(_cc.GetTimeFormsQuery()
.Where(o => o.Start>= weekrange.startdate
&& o.End<= weekrange.enddate
&& o.USERID== "TEST"));
However I have 3 tables which connect to this TimeForm table, in sql my query looks like this:
SELECT T* FROM TimeForm
INNER JOIN CLIENT ON TimeForm.CODEID= CLIENT.CODEID
INNER JOIN RATE ON TimeForm.RATEID= RATE.RATEID
INNER JOIN TASK ON TimeForm.TASKID = TASK.TASKID
How can this be possible with the above syntax? I need some values from these tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的操作:
PropertyA、B 等只是类型中存在的属性,用于存储从查询返回的数据。而 ColumnA、B 等是联接涉及的表中存在的列。您可以在查询中用实际值替换这些值。
Try something like this:
PropertyA, B, etc are just properties present in the type, which you use to store the data returned from the query. Whereas ColumnA, B, etc are columns present in the tables involved in the join. You can substitute actual values for these in your query.
您需要转到域服务文件(其中定义了 GetTimeFormsQuery())。它看起来像:
,然后添加到它,使其如下所示:
或者在 TimeFrom 实体中调用任何导航属性。
Silverlight 不执行延迟加载,因此您必须在域服务的查询中显式包含这些属性。此外,在域服务上创建一个额外的方法来接受开始和结束日期以及用户 ID 可能是明智的,这样您就不会每次都通过网络拉动整个表。
重建 Web 项目后,您将在 silverlight 中拥有一个名为 GetTimeFormsWithStartAndEndQuery 的方法,并以这 3 个参数作为参数。
祝你好运!
You need to go to the Domain Services file (where the GetTimeFormsQuery() is defined). It'll look something like:
, and add to it so it is like this:
Or whatever the navigation properties are called in your TimeFrom entity.
Silverlight doesn't do lazy loading, so you'll have to explicitly include these properties in the query in the domain service. Also it's probably wise to create an extra method on the domain service that accepts the start and end date and userid so that you don't pull the entire table over the wire every time.
After you rebuild your web-project, you'll have a method called GetTimeFormsWithStartAndEndQuery in your silverlight with these 3 as parameters.
Goodluck!