none
CreateDatabase for views and stored procedures RRS feed

  • Question

  • I read somewhere that CreateDatabase() was meant to be used, for example, by client applications that needs to install a database at runtime when they are started. If so, you would imagine that CreateDatabase() would create not only tables but also views and stored procedures. I tried with views and they were created, sort of :-(, but as tables. Anyone out there who knows how this is supposed to work. What does CreateDatabase support?

    BTW: I really love the CreateDatabase() call. It is extremely helpful for unit testing database code. If only it could also handle:

    • default values
    • cascading deletes
    • views?
    • stored procedures?


    /Måns

     

     

    Tuesday, September 9, 2008 5:23 PM

Answers

  • CreateDatabase can handle simple tables and associations.

     

    The contents of user-defined functions, stored procedures, triggers, and check constraints are not represented by the attributes. Since all of the above objects are programming constructs it will be difficult for LinqToSQL to figure out the structure of what is expected.

     

    Views can only be interpreted as tables because of the same above reason, since its based on query and LiqToSQL will not know how to handle it.

     

    However cascade delete can be handled by adding [Association.... DeleteRule="CASCADE" ....] to Association attribute.

     

    ~Deepti

    Tuesday, September 9, 2008 6:25 PM

All replies

  • CreateDatabase can handle simple tables and associations.

     

    The contents of user-defined functions, stored procedures, triggers, and check constraints are not represented by the attributes. Since all of the above objects are programming constructs it will be difficult for LinqToSQL to figure out the structure of what is expected.

     

    Views can only be interpreted as tables because of the same above reason, since its based on query and LiqToSQL will not know how to handle it.

     

    However cascade delete can be handled by adding [Association.... DeleteRule="CASCADE" ....] to Association attribute.

     

    ~Deepti

    Tuesday, September 9, 2008 6:25 PM
  •  Måns Tånneryd wrote:

    I read somewhere that CreateDatabase() was meant to be used, for example, by client applications that needs to install a database at runtime when they are started. If so, you would imagine that CreateDatabase() would create not only tables but also views and stored procedures. I tried with views and they were created, sort of :-(, but as tables. Anyone out there who knows how this is supposed to work. What does CreateDatabase support?

    BTW: I really love the CreateDatabase() call. It is extremely helpful for unit testing database code. If only it could also handle:

    • default values
    • cascading deletes
    • views?
    • stored procedures?

     

    CreateDatabase only supports basic table definitions - even indexes are excluded so I would not recommend using it for creating databases during deployment.

    Wednesday, September 10, 2008 4:41 AM
    Answerer