0

I have an application that uses a model on Entity Framework. Is there any function (in DBContext etc) by calling which I can create all tables associated with this model in the database or create a single table that I specify?

2 Answers 2

0

You can use Code First Approach to do this. http://www.entityframeworktutorial.net/code-first/entity-framework-code-first.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

I am using the code first approach. I have a .NET class library which contains the model classes and DBContext. Now I have a client application which will instantiate the DBContext class...When the application starts up, the model tables are not created in the DB. My need is to know whether there is a function call(Say CreateAllTables) in the DBContext class or associated classes which will create all the tables in the DB. Or a function like CreateTable which will create the table I specify
This is not a good approach @Partha that perform DDL operation in application run time. choose package manager console and select the class library and implement the Code First Approach. But if you really want to do it, see this link stackoverflow.com/questions/39807101/…
0

If you're using a Code First approach then Entity Framework will build the table for you. It looks like you are not using Code First, so you will have create the table in the database. I assume you're using an Entity Data Model (.edmx)? If so, you will create your table in the database, then update your data model (.edmx). If you have not yet created your .edmx file, you need to do that - the .edmx file will contain all your CRUD operations.

1 Comment

I have a .NET class library which contains the model classes and DBContext. Now I have a client application which will instantiate the DBContext class...When the application starts up, the model tables are not created in the DB. My need is to know whether there is a function call(Say CreateAllTables) in the DBContext class or associated classes which will create all the tables in the DB. Or a function like CreateTable which will create the table I specify. Note: I have not specified the database server and database name in app.config,I am specifying a connection string while creating DBContext

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.