Lambda expression in dlinq attribute

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrus

    Lambda expression in dlinq attribute

    I need to use lambda expressions or other way to
    specify default query for dlinq entity type.
    Code below causes compile error shown in comment.
    How to fix ?
    Maybe to use [QueryAttribute( "Supplier", "d=>
    d.Discriminator ==""Domestics "" ")] ?

    Andrus.

    using System;
    using System.Linq;

    // '<' unexpected : attributes cannot be generic
    [QueryAttribute< Supplier>(d=d.D iscriminator==" Domestics")]
    class DomesticsSuppli er {
    public string Discriminator { get; set; };
    public string Name { get; set; };
    }

    class QueryAttribute< TEntity: Attribute {
    IQueryable<TEnt ityQuery;
    internal QueryAttribute( IQueryable<TEnt ityquery) {
    Query = query;
    }
    }



  • Marc Gravell

    #2
    Re: Lambda expression in dlinq attribute

    Well, the compiler message is clear enough; you would have to pass a
    Type through, not a generic. Also, your lambda isn't an IQueryable<T>
    - it is a Func<T, boolor an Expression<Func <T, bool>- but I doubt
    you could use iether directly in an attribute.

    I would suggest something like
    [QueryAttrubute( Condition="Supp lierDiscriminat or",
    Type=typeof(Sup plier)]
    ....
    public static Expression<Func <Supplier, bool>SupplierDi scriminator {
    get {return d=d.Discriminat or=="Domestics" ;}
    }

    (I would make Type optional, defaulting to the current)

    Note that this usage is very different (as I understand it) to how
    NHibernate uses QueryAttribute, and you'll need to code it up by
    hand...

    Marc

    Comment

    • Marc Gravell

      #3
      Re: Lambda expression in dlinq attribute

      Additional; my unserstanding is that EF supports much better
      inheritance than LINQ-to-SQL; a taster is here:


      Marc

      Comment

      • Marc Gravell

        #4
        Re: Lambda expression in dlinq attribute

        Also:
        live Draw Hongkong Hari Ini memuat semua pengeluaran Hongkong, Live Result Hongkong, Live Toto HK Tercepat Hari ini

        Comment

        • Marc Gravell

          #5
          Re: Lambda expression in dlinq attribute

          Actually, it looks like LINQ to SQL supports
          InheritanceMapp ingAttribute, and IsDiscriminator on ColumnAttribute .

          Comment

          • Marc Gravell

            #6
            Re: Lambda expression in dlinq attribute

            Well, since .NET has single inheritance, you can't have two dimensions
            of discriminator.. . could you perhaps simply map the two columns into
            a single discriminator column? This sound like something EF could
            handle (perhaps), or maybe a UDF when reading... but to be honest I
            think two discriminators is making life hard...

            Comment

            Working...