c# - Bulk insert using code first migrations for azure -
we have lot of data needs loaded number of tables. far can see have 2 options:
include data part of configuration class seed method problems 1.a. slow , involve writing lot of c# code)
use bulk insert code first migrations - lot quicker , better solution. problems 2.a. may prove tricky working other data gets loaded same tables part of seed. 2.b. requires sql identity insert switched on.
what solution best , if 2 how go bulk insert code first migrations , how can address problems?
bypassing ef , using ado.net/sql approach bulk data upload. best approach depends on whether want data inserted part of migration or logic runs on app start.
- if want inserted part of migration (which may nice since don't have worry defensive checks if data exists etc.) can use
sql(string)
method execute sql uses whatever format , sql features want (including switching identity_insert on/off). in ef6.1 there overload allows run .sql file rather having in code string. - if want on app start, create instance of context , access
database.connection
raw sqlconnection , use ado.net directly insert data.
Comments
Post a Comment