The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Stored View vs. Dynamic Query

Last post 08-08-2008, 11:01 PM by TrevorW. 8 replies.
Sort Posts: Previous Next
  •  08-07-2008, 5:37 AM 10607

    Stored View vs. Dynamic Query

    What are the advantages\disadvantages of a View stored in a database versus a Dynamic Query?

    I am new to .Net and ES and I am still trying to wrap my head around a lot of basic design issues.  When I create my edit forms, I like to present the user with a read-only grid listing the available records.  When they select the record that they want to edit, I like to give them a modal dialog where I can control their editing experience (and also force then to save\cancel on a record by record basis).  I want to bind the grid to a view\query so that I can more easily alow filtering\sorting on related fields.  Which should I use ... a stored view or a dynamic query?

  •  08-07-2008, 6:52 AM 10609 in reply to 10607

    Re: Stored View vs. Dynamic Query

    Hi
     
    In my mind there are 2 main purposes/uses for Views.  The first being access control, the second being for exactly the type of scenario you're talking about here - namely, presenting information from a number of tables, using meaningful data from each (rather than FK field values etc).
     
    In my case for example, I have tables like the following
    Person
    Contacter
    Employee
     
    (Person holds info common to both, and has a 0-1 relationship with Contacter and Employee tables - well, 2 x one-to-one relationships really).  Anyway, in order to easily present info in a grid, I have an "EmployeeView" and a "ContractorView" that pulls in relevant info from each of the relevant tables, along with additional info from other tables too.
     
    So I use the above views to present info in a (readonly) grid, when I want to update, I do the same as you (I think) in that I display a modal form with info from the individual tables bound to the appropriate controls etc, and update the individual entities (inside a transaction where appropriate).
     
    So I think you're using views for the right reason, but that's just my opinion, others may of course vary
     
    Cheers
    Martin
  •  08-07-2008, 7:22 AM 10610 in reply to 10609

    Re: Stored View vs. Dynamic Query

    Yes, that is exactly what I am trying to do.  Actually, I use a single form with the grid on one page of a pageframe and the editing on one or more other pages, but functionally it is the same as using a modal form.  It is reassuring to know that my approach makes sense to someone else.

     What do you think?  Does it matter whether I use ES Dynamic Query and generate my grid view on the fly OR should I use a view that is predefined and stored right in the database.

  •  08-07-2008, 7:36 AM 10611 in reply to 10610

    Re: Stored View vs. Dynamic Query

    Our design philosophies seem pretty consistent. Up until about six months ago, I worked pretty much as Martin has described. Views for the read-only grids, LoadByPrimaryKey in a modal Add/Edit dialog, Save() on OK. But, since the addition of Joins in the December ES2007 release, I have taken a different approach in newer projects.

    The read-only grids and modal dialogs are still there, but rather than having to open SQL Server Management Studio, putting on my SQL syntax thinking cap, and designing a View, I add methods in the custom classes that use EntitySpaces DynamicQuery to accomplish the same thing. Now, all my code is written in one language (C# in my case), and can be maintained within Visual Studio. When the database schema inevitably changes, I get compile errors in my business class method after re-generating, rather than runtime errors, if I forget to change one of the Views.

    As Martin says... not going to work for every project... just some food for thought.


    David Neal Parsons
    www.entityspaces.net
  •  08-07-2008, 8:03 AM 10612 in reply to 10611

    Re: Stored View vs. Dynamic Query

    I use the same approach as David and the result is fantastic.

    Even better with joins. Without joins we were kind of limit. but now, not anymore.

    Mantain views is much pain than mantain C# code.

    The great advantage is what david said:

    When the database changes, you get compile errors in you class, rather than runtime errors.

    You don't have inespectable errors because you accidentaly forget to change the view.

     

     

  •  08-07-2008, 8:06 AM 10613 in reply to 10611

    Re: Stored View vs. Dynamic Query

    Wow!  I like the sound of keeping everything in C#, especially because I may have to support different back ends.  I really love what ES is doing for me.  I am going to be able to keep all of my logic in one spot.

    Are there any good examples of how to set up the methods in a custom class to achieve all of this?  Are there any sample applications doing read-only grids with modal edit?

  •  08-07-2008, 8:28 AM 10614 in reply to 10613

    Re: Stored View vs. Dynamic Query

    Well, not too complicated.

    Choose an EntityCollection where the Custom Load method (your view in this scenario) will be.

    Create as many custom methods as you wanted that load the object collection using dynamic query, joins, filters, etc.

    Simple use these method in your form.

     

  •  08-08-2008, 10:22 AM 10627 in reply to 10614

    Re: Stored View vs. Dynamic Query

    I agree.  Adding a custom method is not too complicated. 

    But...

    Putting it all together to create a well behaved read-only grid with a modal add\edit forcing record by record save\cancel is not a trivial exercise.  Especially for someone like me who is still climbing the learning curve.  Does anyone have an example app that might help?

  •  08-08-2008, 11:01 PM 10637 in reply to 10627

    Re: Stored View vs. Dynamic Query

    All I have to say is database independence is awesome! I don't use views and I don't use stored procedures.

     I love this link:

    http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html

    With ES, views and stored procedures are both EVIL - IMO because of the database indepenedence as well as many points noted in the link above.

    There area a few exceptions, but hey - just one guy's opinion.

View as RSS news feed in XML