IStartupTask连接数据库的方法
来源:学问馆 本文已影响6.78K人
来源:学问馆 本文已影响6.78K人
系统启动时执行任务:IStartupTask,启动时执行的任务主要是数据库的初始化和加载。
IStartupTask调用IEfDataProvider进行数据库的初始化。
IEfDataProvider,SqlCeDataProvider:获取数据连接工厂,不同类型数据库,连接工厂不同。
接口IStartupTask的.实体类EfStartUpTask的实现如下:
public class EfStartUpTask : IStartupTask { public void Execute() { var settings = lve
SqlCeInitializer,CreateCeDatabaseIfNotExists初始化数据库。
IDbContext,NopObjectContext系统数据库操作上下文。加载所有数据库映射类:EntityTypeConfiguration
protected override void OnModelCreating(DbModelBuilder modelBuilder) { //dynamically load all configuration // configType = typeof(LanguageMap); //any of your configuration classes here //var typesToRegister = ssembly(configType)ypes() var typesToRegister = xecutingAssembly()ypes() e(type => !llOrEmpty(space)) e(type => Type != null && nericType && enericTypeDefinition() == typeof(EntityTypeConfiguration<>)); foreach (var type in typesToRegister) { dynamic configurationInstance = teInstance(type); (configurationInstance); } // do it manually below. For example, //(new LanguageMap()); delCreating(modelBuilder); }
此方法是继承自DbContext。并在系统启动时调用,建立数据表与实体的对应关系。
在类型依赖注册类ndencyRegistrar中实现数据库工厂的创建、数据库的加载。如下代码:
//data layer var dataSettingsManager = new DataSettingsManager(); var dataProviderSettings = Settings(); ster(c => Settings())
接口IEfDataProvider 的实体类SqlServerDataProvider的数据库初始化方法如下:
///
public override void SetDatabaseInitializer() { //pass some table names to ensure that we have nopCommerce 2.X installed var tablesToValidate = new[] {"Customer", "Discount", "Order", "Product", "ShoppingCartItem"}; //custom commands (stored proedures, indexes) var customCommands = new List
另外,EntityFramework本事是ORM框架,通过数据库访问上下文建立与数据库的连接及实体与数据表的对应广西。并通过创建IRepository
PEP4 Unit3 Is this your skirt英语评课稿
i recall with embarrassing clarity the flavor of those particular ashes ?
英文简历(市场助理)MARKETING ASSISTANT
astronaut是什么意思-astronaut的中文翻译-常见例句
Assistant Marketing Director简历范文
Unit10 You’re supposed to shake handsB评课稿大纲
Thats what it is there for这句话包含了那些连读规则?
MARKETING ASSISTANT电子简历模板
《Whats sixty plus thirty?》教学感悟
astronaut是什么意思-astronaut音标及相关短语
64位Vista、Windows7系统IIS连接数据库故障完美解决方法
Snapchat 为何开始试水类 Path 的 ‘Stories’ 社交功能?
Taking-pictures的教学反思
nike+ sportswatch同步到网站的数据可以再同步到手机app上吗?
利用Kickstart自动化安装CentOS的方法
英语四级考试备考作文Protecting the Intangible Cultural Heritages训练题
Matt Stuart - 趣味街头摄影师
修改trustedinstaller权限方法
中考英语作文范文 :Times Supermarket
RECRUITER(Human Resources Department)电子简历模板
初三英语满分作文The Ways for Students to Relax
数据库的意思解释
英语作文:广告是诅咒 Advertisement is a Curse
六年级下册PEPUnit4PartBLet’slearn的评课稿
《Unit2The tiger lives in Asia》评课稿范文
administrator什么意思-administrator读法音标
Unit 6 I like music that I can dance to评课稿范文
计算机信息管理数据库方向专业的求职信
数据库工程师
数据库and和or的用法区别
what is happiness to you教学案例
三年级上册Unit2 Clurs PartA 第1课时 课后反思
8B Unit 3 Integrated skills的评课稿
葡萄牙语的历史:Revolucionários apossam-se de Porto Alegre
PHP数据库连接的方法
在QQ音乐里搜索到演奏家是various artists是真人弹的吗?
冀教版三下Lesson10《In the Restaurant》的教学反思
BreakfastLunchandSupper英语的教学
初中英语Unit 2 .What’s the matter优秀教学设计
高分英语范文:In My Father’s Suitcase
Unit Three is this your skirt教学设计范文