Dynamic LINQ

6 posts, 1 answers
  1. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 14 Mar 2009 Link to this post

    var wherePart = "q.SkuUid == SkuUid and q.SalesType == SalesType";   
     
    var getIt from q in query    
    where wherePart    
    select q;    
     

    Is dynamic LINQ, like the above, included in Q1 2009?
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 17 Mar 2009 Link to this post

    Hi Bo Hessner,

    dynamic LINQ is supported, but the example given by you must be slightly rewritten:

     var getIt = scope.Extent<Bo>()
    .Where("SkuUid == @SkuUid and SalesType == @SalesType", 1234, 5678);

    So the entire query cannot be made up by string concatenation, but string pieces must be given along with the parameters in the right order.
    You might want to check this link also : Dynamic LINQ .

    Kind regards,
    Alexander
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 17 Mar 2009 Link to this post

    Hi Hessner,

    There was a little misunderstanding in our last letter to you. The format of the dynamic Linq query should be slightly different:

     var getIt = scope.Extent<Bo>()
    .Where("SkuUid == @0 and SalesType == @1", 1234, 5678);

    The thing is that named parameters are not supported at the moment with OpenAccess and numbed parameters should be used instead.

    Again we are sorry for the inconvenience.


    All the best,
    Zoran
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 17 Mar 2009 Link to this post

    Regarding:

     var getIt = scope.Extent<Bo>()
    .Where("SkuUid == @SkuUid and SalesType == @SalesType", 1234, 5678);

    My real "where part" contain fields from several tables, how is this done?
    var getIt = scope.Extent<table1 Join table2 Join table3 >?
    .Where("table1.SkuUid == @SkuUid and table2.SalesType == @SalesType", 1234, 5678);
  6. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 17 Mar 2009 Link to this post

    Hello Hessner,

    You should just point the references in the where clause like in the sample bellow which is based on the
    Northwind database.

    var result = scope.Extent<Order>() 
            .Where("Customer.CustomerID == @0 and Employee.EmployeeID==@1 ""ALFKI",1); 
     


    All the best,
    Zoran
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 17 Mar 2009 Link to this post

    I got it - this work out fine:

    var condition = string.Format("PortalID == {0}", Utilities.CurrentPortalid());  
    var result = os.Extent<UserRole>().Where(condition).Select("new (User.UserID, User.Email, User.FuldeNavn, Medlemsnummer, Role.RoleName, SidsteLogon)");  
    RadGrid1.DataSource = result;  
     
Back to Top
DevCraft banner