Greg,

We're using EF 4 on a fairly large project, but we're not doing any
Entity SQL, it's mostly all Linq to EF with some stored procs thrown
in the mix (for the specific SQL Server 2008 bits we need - like
filestream, spatial stuff etc)

In the above example that you have we'd do something like this:

var results = CreateObjectQuery() as IQueryable<MyObject>;

if(myParamVal != null)
{
   results = results.Where(mo => mo.myParam == myParamVal);
}

if(myOtherParamVal != null)
{
   results = results.Where(mo => mo.myOtherParam == myOtherParamVal)
}

return results; // or select or whatever you'd like to do here.


I know this isn't directly what you are discussing, but it's how we
are solving that particular issue for optional parameters.  Also can't
comment on the actual SQL that this generates as it hasn't caused us
any performance issues yet to look at it.

Hope this is useful,

Neil.

On 26 January 2011 18:54, Greg Keogh <[email protected]> wrote:
> Folks, is anyone here using the EF4 in anger? I've been studying Julia
> Lerman's O'Reilly book Entity Framework for weeks, and jeez it's a lot to
> digest. Sometimes I'll read a chapter and think it all makes sense, then
> find when I sit down to code that I have to go back and read it again, then
> I usually have to go back to the chapter that introduces that chapter. I
> think it will take months to get EF4 in perspective. There are lots of
> classes, layers and tricks, and it's easy to get them mixed up and lose
> sight of the big picture of how it all hangs together.
>
>
>
> I'm playing with ObjectQuery and I'm having trouble with null parameters. In
> the Entity SQL I want to have a condition in a WHERE clause like this:
>
>
>
> WHERE ((@paramval IS NULL) OR (foo.Something = @paramval))
>
>
>
> This is a typical piece of a WHERE clause where you want to filter on a
> parameter value only if it's specified. In T-SQL for SQL Sever and CE this
> is works okay. In Entity SQL I have found that I can't pass null or
> DBNull.Value as the @paramval parameter value. Nor can I omit the parameter
> if it's null.
>
>
>
> I need to build a huge Entity SQL WHERE clause with multiple conditions like
> the one above and it doesn't seem possible so far. Has anyone dabbled in
> this?
>
>
>
> Greg
>
>
>
>

Reply via email to