Linq或存储的proc-我应该选择哪个? [英] Linq or Stored proc - Which should I choose?

查看:71
本文介绍了Linq或存储的proc-我应该选择哪个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

活动发生在特定日期的某个位置,但是每个活动可以在不同日期的相同或不同位置重复.我已经创建了一个实体框架模型,并希望使用在两个日期之间发生的相关活动来填充它,并按与指定位置的位置距离进行排序.

An Activity occurs at a location on a specific date, but each activity may be repeated at the same or different locations on different dates. I have created an entity framework model, and wish to populate it with relevant Activities which occur between two dates, ordered by the locations distance from a specified location.

因此,我有以下表格:

活动(A)

发生(O)

位置(L)

具有如下关系:

A 1-n O n-1 L

A 1-n O n-1 L

使用linq对实体执行此操作时遇到一些困难,但是请确保我可以在存储过程中实现它.

I am having some difficulty in doing this using linq to entities, but am sure that I can achieve it in a stored procedure.

这是我可以使用Linq进行的操作吗?还是Linq创建Sql的问题太复杂了?如果可以的话,任何有关编写Linq查询的指针都将不胜感激.

Is this something that I should be able to do using Linq or is it too complex a problem for Linq to create the Sql? Any pointers about writing the Linq query would be appreciated, if it is something that it should be able to do.

推荐答案

var query = from occurrence in occurrenceList
            join activity in activityList on occurrence.ActivityID equals activity.ID
            join location in locationList on occurrence.LocationID equals location.ID
            let distance = CLocation.Distance (referenceLocation, location)
            orderby distance, activity.Name
            where start <= occurrence.Date && occurrence.Date <= end
            select new
            {
                ActivityName = activity.Name, 
                LocationName = location.Name,
                Distance = distance,
                Date = occurrence.Date
            };

这篇关于Linq或存储的proc-我应该选择哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆