none
Linq Create New Table from Code ? RRS feed

Answers

  • Yes, you can create a Database with as many tables as you need form code. All you need is a Server where you have the proper rights.
    Use simple SLQ-Commadns and Connections for that, the syntax is a SQL issue first.

    However, you should avoid needing too do that. If you need a single user Database, use a embeded one and create/make a copy of the empty original DB during installation.
    General rules about where (not) to place files with neesesary write access apply:
    http://www.thecodeking.co.uk/2007/03/making-your-application-uac-aware.html

    If your application is a bit more complex, consider just handing the admin the SQL that creates the DB tell him to execute it "on a suiteable server" and let him deal with it (your programm needs the ability to configure the Connection string somewhere, of course).


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Tuesday, April 1, 2014 6:02 PM

All replies

  • Linq2Entities and Entity Framework is an ORM tool which provides the data access functionality. I think for creating tables dynamically you should use standard SQLCommand object and call ExecuteNonQuery() method. Hope this helps!


    Ovais Mehboob Ahmed Khan http://ovaismehboob.wordpress.com

    Tuesday, April 1, 2014 5:21 PM
  • So is this all contained within the System.Data.Sql library ?
    Tuesday, April 1, 2014 5:40 PM
  • Why are you trying to do this?  Will your app create this table every time it runs?

    What workflow are you using for Entity Framework?  Database-First? Code-First?

    David


    David http://blogs.msdn.com/b/dbrowne/

    Tuesday, April 1, 2014 5:47 PM
  • Yes, you can create a Database with as many tables as you need form code. All you need is a Server where you have the proper rights.
    Use simple SLQ-Commadns and Connections for that, the syntax is a SQL issue first.

    However, you should avoid needing too do that. If you need a single user Database, use a embeded one and create/make a copy of the empty original DB during installation.
    General rules about where (not) to place files with neesesary write access apply:
    http://www.thecodeking.co.uk/2007/03/making-your-application-uac-aware.html

    If your application is a bit more complex, consider just handing the admin the SQL that creates the DB tell him to execute it "on a suiteable server" and let him deal with it (your programm needs the ability to configure the Connection string somewhere, of course).


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Tuesday, April 1, 2014 6:02 PM
  • I'm using the Entity Framework - Database-First
    Tuesday, April 1, 2014 7:11 PM
  • Then why are you trying to create a table in code?  Just use SSMS, or SSDT, or even SqlCmd to create your table, and then refresh your model.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Tuesday, April 1, 2014 7:57 PM
  • Yes you can use SQLCommand object, write a query like Create Table... and then call ExecuteNonQuery() method.. It will definitely create a table programmatically...

    Ovais Mehboob Ahmed Khan http://ovaismehboob.wordpress.com


    Tuesday, April 1, 2014 8:15 PM