开发者

How to populate a database using entity framework

开发者 https://www.devze.com 2023-02-20 00:16 出处:网络
When you use the feature \"generate database from model\" how do you put some data into a table? for example i want a tabel with all country after the database is created.

When you use the feature "generate database from model" how do you put some data into a table?

for example i want a tabel with all country after the database is created.

Is there a script / shortcut to do th开发者_JAVA百科is?


You have following options

  • write a program to create db/table and insert data

  • create SQL script to create db/table and insert data

  • use the database management tool (e.g. Management Studio for SQL Server) to create db/table and insert data


Are you looking for the Seed() method?


Accepted Ajay_Whiz answer since it helped me the most i created a bat file that just executes the contex.sql and then some other *.sql files to populate the database.

Disclaimer this is for development database do not ever ever use this on you productions database. unless you know what your doing

The generated contex.edmx.sql by Entity framework drops all your data!!!

::Automated databasecreater
@echo off
echo createing database
SQLCMD -S. -E -iContext.edmx.sql -e -b
echo add gemeentes
SQLCMD -S. -E -iContainsDataOfTableX.sql -b
pause
0

精彩评论

暂无评论...
验证码 换一张
取 消