0

I'd like to be able to create tables, or to create the necessary SQL to create a table from an existing class (with DataAnnotations.) Basically the same thing that VS does for you automagically with migrations. I'd like to be able to control table creation in the app.

Can't find any documentation on this, or don't know where to look.

This article is referenced in many posts, but it relies on VS magic and doesn't get into writing it into the application.

pixelmike
  • 1,973
  • 1
  • 19
  • 31
  • Did you mean to say "Migrations" or "Code First"? What you're describing sounds like "Code First", which should not require Visual Studio. Migrations is to help you migrate from one version of a database to a future version where perhaps columns are added/removed or other structural changes are made to the database. – devuxer Dec 21 '15 at 23:31
  • Ah, yeah, sorry I did conflate the two. I think I mean "Code First", however the tables seem to get created automatically when the app is run. I'd like to be able to control that, or to tell it to create specific tables at run time, or to generate the create table SQL for me as a string. – pixelmike Dec 22 '15 at 01:35
  • Are you asking for some prebuilt library, or advice on how to build such a thing from scratch? – James Dec 22 '15 at 05:05
  • Well since .NET does this for you somehow automatically on app startup, I figured there should be a way to make use of it in your app. If it's actually not usable in this way then sure, you can suggest a 3rd party library if you know of one. [This answer](http://stackoverflow.com/questions/47239/how-can-i-generate-database-tables-from-c-sharp-classes/47273#47273) shows a rough implementation from scratch, but again I figured there would be some way to use the built in functionality with more granular control than "it happens automatically on first run". – pixelmike Dec 22 '15 at 05:48

1 Answers1

0

It looks like the System.Data.Entity namespace provides access to the lower-level functionality of EF.

pixelmike
  • 1,973
  • 1
  • 19
  • 31