none
Dynamic queries? RRS feed

  • Question

  • Hi all,

    I have the following scenario:

    I have a model nicely set up. Each entity is linked to a database table. Each database table has its own "search view". This view almost always have more fields than the table itself (eg. a FK in the table will not be in the view but the "name" or "description" fields of the FK table). This should not be imported into the model because it will double its size.

    Furthermore, I have a special "listcolumns" table that lists one or more fields from the view depending on use. This means that for a particular user certain fields will be returned, whilst for another user another set of fields can be returned. This table includes additional properties such as width, sorting and header label.

    Now, my form has a number of controls and the user can enter text wherever he wants. When he clicks on "Search", a dynamic query must be built depending on the filtering he entered, the view and the columns that will be returned.

    My question is: Is this scenario possible to code using EF without a lot of additional coding, or should I code everything myself and skip EF and use DataSets?

    Thanks,

    Ivan



    • Edited by Cryo75 Saturday, May 12, 2012 3:51 PM
    Saturday, May 12, 2012 3:45 PM

Answers

All replies

  • Hi Cryo75,

    Welcome to MSDN Forum.

    You can use Dynamic Linq to create your dynamic query. Dynamic Linq can help you to create Linq query by contenting string, likes the traditional ado.net dynamic query creation. Please refer to the link, this link introduces about Dynamic Linq and provides the download link.

    Best Regards


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

    Sunday, May 13, 2012 1:55 PM
    Moderator
  • Hi Ivan;

    Entity Framework does support dynamic query natively with the use of Entity Framework ESql, Entity SQL, the information can be found on the following web pages.

    Entity SQL Overview
    Entity SQL Reference
    Entity SQL Language

      

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Sunday, May 13, 2012 2:34 PM
  • Is it possible not to add the views as entities in the model but query them as they were objects (maybe creating them at runtime)?
    Sunday, May 13, 2012 6:59 PM
  • Hi Ivan;

    Microsoft T-SQL server views are accessed as any other table in a database. Please see this article "How to Use SQL Server Views with the Entity Framework".

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Sunday, May 13, 2012 7:20 PM
  • You can use ESql to query them.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Sunday, May 13, 2012 7:21 PM