Generic LINQ DAL

6 posts, 0 answers
  1. Joebet
    Joebet avatar
    23 posts
    Member since:
    Jun 2010

    Posted 19 Jul 2010 Link to this post

    Good day guru. Im having trouble in manipulating data using Telerik ORM with LINQ. What I am trying to accomplish is to make a dynamic or generic LINQ that will access my database. that is...

    var result = from o in scope.Extent<ENTITY>()
                 where o.Customer.Contains("John")
                 select o;
    scope.Transaction.Begin();
    scope.Remove(result.ToList());
    scope.Transaction.Commit();
    scope.Dispose();

    I need to make the above code a function that is reusable to all programmer by just supplying the above capitalized "ENTITY" which corresponds to the actual entity properties generated by telerik. ie. Product, Customer, Supplier or anything the user wants.. 

    Thanks...

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 19 Jul 2010 Link to this post

    Hello Joebet,
    You can use our own string based query langauge OQL or you can use dynamic Linq where you use Linq syntax but with strings.

    Best wishes,
    Jan Blessenohl
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Joebet
    Joebet avatar
    23 posts
    Member since:
    Jun 2010

    Posted 19 Jul 2010 Link to this post

    Do OQL have the CRUD functionality? because the documentation only shows the "Select" statement. Also i read the tutorial links your provided but what I am trying to accomplish is indeed a dynamic linq but with the actual entity being the parameter all that you had given was making a dynamic where and order by linq and the entity to be referred was predefined. Sorry for my bad english im not really good at explaining things. but is it clear? thanks and im hoping for a swift reply.
  5. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 20 Jul 2010 Link to this post

    Hello Joebet,
    Do you want to do the delete as part of the query? That is indeed not possible. Both query languages are only meant for reading data. You have to stay with your code or use an additional ADO connection to do such operations. ORMs are by design bad in mass operations and if your list, that you want to delete, is bigger I count this as such.

    Best wishes,
    Jan Blessenohl
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 08 May 2012 Link to this post

    One of the original questions was asked twice, but still never answered...

    Can the ENTITY (i.e. the TABLE NAME) in a LINQ/Lambda query be dynamic?
    Yes, we know stuff inside the WHERE, ORDERBY, etc... can be dynamic.

    Example:
    dbContext.DYNAMICENTITYs.Where(Function(db) db.Code = "123").ToList

    Can the "DYNAMICENTITY" above be made generic/dynamic?

    For example...
    Let's say you have 100 entities/tables with the same structure... different entity/table names.
    You want to use ONE LINQ/Lambda statement to query (like above).

    Can you use a STRING value in some way to define one of the 100 tables/entities, but use ONE LINQ/Lambda query??

  7. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 09 May 2012 Link to this post

    Using an interface over your common persistent properties could be used:

    IQueryable<T> FilterName<T>(string name) where T : IMyNamedIfc
    {
        return context.GetAll<T>().Where(x => x.Name.Contains(name));
    }

    interface IMyNamedIfc
    {
        stirng Name { get; }
    }

    class MyPersistentClassA : MyNamedIfc
    {
        public string Name { get; set; } // persistent
    }

    class MyPersistentClassB : MyNamedIfc
    {
        public string Name { get; set; } // persistent
    }

    Then a
    var resultA = FilterName<MyPersistentClassA>("hello").ToList();
    var resultB = FilterName<MyPersistentClassB>("world").ToList();
    should be possible.

    The other option includes using dynamic LINQ.

    Regards,
    Thomas
    the Telerik team
    Follow @OpenAccessORM Twitter channel to get first the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top
DevCraft banner