> I've been doing this for about 3 hours, so I may have the wrong end of the
> stick.
>
> While doing the "hello world" type walkthrough I've come across....
>
>             ObjectQuery<Department> departmentQuery =
>                 schoolContext.Department.Include("Course")
>                 .OrderBy("it.Name");
>
> Now I'm a bit confused as to what an object query is, but this doesn't
> look nice...."Course" and "it.Name"...are going to give me runtime errors
> if (when) something changes.
>
> I'm a bit confused as to how this sits with Linq....is there a Linq query
> that I can use in the above which is typesafe and is of type
> ObjectQuery<Department>?

        The '.Include("Course")' part won't be possible to make type safe,
unless you write your own extension method, pass in an entity type and return
a MethodCall expression to Include passing in the string. Why they haven't
done that is beyond me, also why they haven't added more eager loading options
like filters etc.

        The .OrderBy can be rewritten as:

        from d in schoolContext.Department.Include("Course")
        orderby d.Name ascending
        select d;

        at least, that's how standard linq queries would do it.

                FB


------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to