DbContext SQLite設定檔

來源:互聯網
上載者:User

標籤:false   odi   頭部   binding   where   public   name   eve   red   

 

<?xml version="1.0" encoding="utf-8"?><configuration>  <configSections>    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />  </configSections>  <connectionStrings>    <add name="connectionSQLite" connectionString="data source=dtcms3.db3" providerName="System.Data.SQLite.EF6" />  </connectionStrings>  <startup>    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />  </startup>  <system.data>    <DbProviderFactories>      <remove invariant="System.Data.SQLite.EF6" />      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />      <remove invariant="System.Data.SQLite" />      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />    </DbProviderFactories>  </system.data>  <entityFramework>    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">      <parameters>        <parameter value="v13.0" />      </parameters>    </defaultConnectionFactory>    <providers>      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />    </providers>  </entityFramework>  <runtime>    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      <dependentAssembly>        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />      </dependentAssembly>    </assemblyBinding>  </runtime></configuration>

 C#代碼

public class SQLiteContext : DbContext    {        public DbSet<Model.manager> manager { get; set; }        public SQLiteContext() : base("connectionSQLite")        {        }        protected override void OnModelCreating(DbModelBuilder modelBuilder)        {            //清除自動產生的資料表名被複數的問題            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();            //自訂表格名            modelBuilder.Entity<Model.manager>().ToTable("dt_manager");        }    }

 自訂表格明方法二

引用命名空間
using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;類名頭部添加[Table("dt_manager")]public partial class manager

 

調用

private void Window_Loaded(object sender, RoutedEventArgs e)        {            SQLiteContext context = new SQLiteContext();            var manager = context.manager.Where(p => p.id == 1).FirstOrDefault();        }

 

DbContext SQLite設定檔

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.