.net – 将Entity Framework 4.1与SQLITE一起使用

.net – 将Entity Framework 4.1与SQLITE一起使用,第1张

概述有可能吗?我有一个现有的数据库,并创建了实体类: public class MyContainer : DbContext{ public DbSet<Item> Items { get; set; } // more tables..} 当我使用此连接字符串时,它失败,因为它没有任何元数据文件: <connectionStrings> <add name="MyC 有可能吗?我有一个现有的数据库,并创建了实体类:

public class MyContainer : DbContext{    public DbSet<Item> Items { get; set; }    // more tables..}

当我使用此连接字符串时,它失败,因为它没有任何元数据文件:

<connectionStrings>      <add name="MyContainer"          connectionString="Metadata=.\items.csdl|.\items.ssdl|.\items.msl;provIDer=System.Data.sqlite;provIDer connection string=&quot;data source=.\mindstore.sqlite.s3db&quot;"          provIDername="System.Data.EntityClIEnt"/>  </connectionStrings>

但是,当我从配置中省略元数据时,它会抱怨您不允许从配置中省略元数据.

那么如何在不使用任何xml配置文件的情况下将sqlITE与EF 4.1一起使用,并按照惯例进行映射呢?

解决方法 如果要在没有EDMX的情况下首先使用EF代码,则无法使用EntityClIEnt.使用sqlite的常见ADO.NET连接字符串:

<connectionStrings>        <add name="MyContainer" provIDername="System.Data.sqlite"         connectionString="data source=.\mindstore.sqlite.s3db" /></connectionStrings>

编辑:

要关闭数据库创建和数据库检查,请尝试删除默认元数据约定并将数据库初始化程序设置为null.

数据库初始化器:

// call this only once in your application bootstrapDatabase.Setinitializer<YourContext>(null);

删除约定:

// Place this to your derived contextprotected overrIDe voID OnModelCreating(ModelBuilder modelBuilder) {    base.OnModelCreationg(modelBuilder);    modelBuilder.Conventions.Remove<IncludeMetadataConvention>();}
总结

以上是内存溢出为你收集整理的.net – 将Entity Framework 4.1与SQLITE一起使用全部内容,希望文章能够帮你解决.net – 将Entity Framework 4.1与SQLITE一起使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1150255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存