none
Query: a proper way to embed expression RRS feed

  • Question

  • First, let's consider following sample query:


    var entries = context.Masters.Where(
                        m =>
                            m.Details.Where(
                                d =>
                                    d.SomeProperty == someValue).Count() > 5);

    First where clause will be Expression<Func<Master, bool>>, but second will be just a IEnumerable.Where() call expression with lambda Func<Detail, bool>, not Expression, because it will be used with IEnumerable Details navigation roperty. So, I'm wondering how Entity Framework works with such expressions, does it decompiles IL? Is there overheads with such queries? If I already have complex Expression for second where clause intended to be embedded on the fly, should I just compile and pass it, or better way exists?

    UPD: passing compiled expression causes exception "Internal .NET Framework Data Provider error 1025"

    Tuesday, May 29, 2012 10:39 AM

Answers

  • Ok, i overcame it. Expression.Lambda<>() should be used with Where call expression to add such filter in runtime, not compiled lambda.
    Tuesday, May 29, 2012 2:49 PM

All replies

  • Ok, i overcame it. Expression.Lambda<>() should be used with Where call expression to add such filter in runtime, not compiled lambda.
    Tuesday, May 29, 2012 2:49 PM
  • Hi AlikDev,

    Welcome to MSDN Forum.

    I'm glad to hear that you have solved the issue, and thanks for your sharing.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 30, 2012 2:07 AM
    Moderator