C# Silverlight在连接时使用实体到LINQ
我有下面的代码,它可以为我获取单个实体的数据C# Silverlight在连接时使用实体到LINQ,c#,silverlight,wcf,entity,ria,C#,Silverlight,Wcf,Entity,Ria,我有下面的代码,它可以为我获取单个实体的数据 LoadOperation<TimeForm> loadoperation = _cc.Load(_cc.GetTimeFormsQuery() .Where(o => o.Start>= weekrange.startdate && o.End<= weekrange.enddate &&a
LoadOperation<TimeForm> loadoperation = _cc.Load(_cc.GetTimeFormsQuery()
.Where(o => o.Start>= weekrange.startdate
&& o.End<= weekrange.enddate
&& o.USERID== "TEST"));
使用上述语法如何实现这一点?我需要这些表中的一些值。尝试以下方法:
var query = context.TimeForm.
Join(context.CLIENT,
t => t.CODEID, c => c.CODEID ,
(t, c) => new
{
PropertyA = t.ColumnA,
PropertyB = c.ColumnB
}).Join(context.RATE,
b => b.RATEID, r => r.RATEID,
(b, r) => new
{
PropertyC = b.ColumnC,
PropertyD = r.ColumnD
}).Join(context.TASK,
x => x.TASKID, t => t.TASKID,
(x,t) => new
{
PropertyE = x.ColumnE,
PropertyF = t.ColumnF
});
public IQueryable<TimeForm> GetTimeForms() {
return this.Context.TimeForm
.Include("Client") // Assuming your property to see the client is called "Client"
.Include("Rate") // Same for "Rate"
.Include("Task"); // and "Task
}
PropertyA、B等只是类型中存在的属性,用于存储查询返回的数据。而ColumnA、B等是联接中涉及的表中的列。您可以在查询中用实际值替换这些值。您需要转到域服务文件(其中定义了GetTimeFormsQuery())。它看起来像:
public IQueryable<TimeForm> GetTimeForms() {
return this.Context.TimeForm;
}
public IQueryable GetTimeForms(){
返回this.Context.TimeForm;
}
,并添加到其中,使其如下所示:
var query = context.TimeForm.
Join(context.CLIENT,
t => t.CODEID, c => c.CODEID ,
(t, c) => new
{
PropertyA = t.ColumnA,
PropertyB = c.ColumnB
}).Join(context.RATE,
b => b.RATEID, r => r.RATEID,
(b, r) => new
{
PropertyC = b.ColumnC,
PropertyD = r.ColumnD
}).Join(context.TASK,
x => x.TASKID, t => t.TASKID,
(x,t) => new
{
PropertyE = x.ColumnE,
PropertyF = t.ColumnF
});
public IQueryable<TimeForm> GetTimeForms() {
return this.Context.TimeForm
.Include("Client") // Assuming your property to see the client is called "Client"
.Include("Rate") // Same for "Rate"
.Include("Task"); // and "Task
}
public IQueryable GetTimeForms(){
返回this.Context.TimeForm
.Include(“Client”)//假设您的财产被称为“Client”
.Include(“Rate”)//与“Rate”相同
.包括(“任务”);//和“任务”
}
或者在TimeFrom实体中调用的任何导航属性
Silverlight不进行延迟加载,因此您必须在域服务的查询中显式地包含这些属性。另外,在域服务上创建一个额外的方法来接受开始和结束日期以及用户ID可能是明智的,这样您就不会每次都将整张表拖过网络
public IQueryable<TimeForm> GetTimeFormsWithStartAndEnd(DateTime start, DateTime end, string userId) {
return this.Context.TimeForm
.Include("Client") // Assuming your property to see the client is called "Client"
.Include("Rate") // Same for "Rate"
.Include("Task") // and "Task
.Where(o => o.Start>= start
&& o.End<= end
&& o.USERID== userId));
}
public IQueryable GetTimeFormsWithStartAndEnd(日期时间开始、日期时间结束、字符串用户ID){
返回this.Context.TimeForm
.Include(“Client”)//假设您的财产被称为“Client”
.Include(“Rate”)//与“Rate”相同
.Include(“任务”)//和“任务”
。其中(o=>o.Start>=Start
&&o.结束