none
Query views/defining queries

    Question

  • I have read about Query views and defining queries but I can't find much in depth about them. How do I create them and are they supported by the designer? I basically want to create a view type entity but I have been told by manager that we can't use views. Regards, Chris. 

    Sunday, October 5, 2008 8:07 PM

Answers

  • Currently, defining queries are not supported by the designer - they require manual editing of the .edmx file. Fortunately, the editing is fairly straight forward. I think this post blog post by Julie Lerman does a good job of describing the basics.

    To distill the process a bit further...

     

    Add a defining query:

    1.Add an EntitySet element to the SSDL section of the .edmx file. Specify only the Name and EntityType attributes of the EntitySet element.

    2. Add a DefiningQuery element to the newly added EntitySet element. Specify the SQL statement to be executed in the body of the DefiningQuery element.

    3. Add an EntityType element to the SSDL section of the .edmx file. This EntityType element must describe the columns that are returned by the SQL statement in the DefiningQuery element.

     

    Add a corresponding entity to the conceptual model:

    4. Add an EntitySet element to the CSDL section of the .edmx file.

    5. Add an EntityType element to the CSDL section of the .edmx file. The Name attribute should have the same value as the Name attribute of the EntitySet element in the preceding step. The properties of the entity type should map to the data returned by the SQL statement that is specified in the DefiningQuery element.

     

    Map the conceptual and storage entity types:

    6. Add an EntitySetMapping element to the Mapping section of the .edmx file that maps the conceptual and storage entities in the previous two procedures.

     

    Hope that helps. We'll add to our documentation soon to cover this scenario in more depth.

    -Brian

    Monday, October 6, 2008 3:57 PM