Silverlight 在连接上使用 Entity to LINQ

发布于 2024-11-16 07:41:14 字数 598 浏览 2 评论 0原文

我有以下代码,它可以工作并为我获取单个实体的数据。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烧了回忆取暖 2024-11-23 07:41:14

尝试这样的操作:

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
                           });

PropertyA、B 等只是类型中存在的属性,用于存储从查询返回的数据。而 ColumnA、B 等是联接涉及的表中存在的列。您可以在查询中用实际值替换这些值。

Try something like this:

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
                           });

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.

陈年往事 2024-11-23 07:41:14

您需要转到域服务文件(其中定义了 GetTimeFormsQuery())。它看起来像:

public IQueryable<TimeForm> GetTimeForms() {
    return this.Context.TimeForm;
}

,然后添加到它,使其如下所示:

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
}

或者在 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));

}

重建 Web 项目后,您将在 silverlight 中拥有一个名为 GetTimeFormsWithStartAndEndQuery 的方法,并以这 3 个参数作为参数。

祝你好运!

You need to go to the Domain Services file (where the GetTimeFormsQuery() is defined). It'll look something like:

public IQueryable<TimeForm> GetTimeForms() {
    return this.Context.TimeForm;
}

, and add to it so it is like this:

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
}

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.

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));

}

After you rebuild your web-project, you'll have a method called GetTimeFormsWithStartAndEndQuery in your silverlight with these 3 as parameters.

Goodluck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文