score:0

Accepted answer
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
            };

score:2

I don't see why that would be impossible to do, or even particularly difficult. Was that the question? :)

The activity table is not interesting to your query as I understand it, start by finding Occurrences. You can include the Activity data in the output like this:

dc.Occurrence.Include("Activity").Where(
    o => o.Date >= startDate && o.Date <= endDate
    && o.Location.DistanceFrom(someLocation) < maxDistance)

DistanceFrom would be however you determine the distance from a location.. I don't how anything about your database design.

If you're using SQL Server 2008 geocoding, I don't think that is supported yet. This article (and this continuation) might be of interest. It's about LINQ to SQL, but the expression building might be of help.

score:0

In Linq2Sql, the designer would automatically create relationships in the L2S classes (but would not display them in the designer)

In Linq2Entities, the designer will display foreign key relationships, but will not automatically create them -- that has to be done manually. (that statement was based on a beta of Linq2Entities --- it may no longer be true).

score:1

I have not used Linq, and maybe I am completely wrong but cant you use stored procedure even if you use Linq? ONE of the main reasons to use Stored procedure is to hide the underlaying datamodel from the business layer. By hiding the datamodel you can optimize the data access. The procedures is used as an interface to application and reports, and if you need to modify the data model this can be done without breaking the interface.

This is my opinion from a DBA perspective. As I said, I have no idea of what the puprose of Linq is.


Related Articles