zoukankan      html  css  js  c++  java
  • EF 6.0 与sql ce 4.0 程序示例

    一、开发工具sharpdevelop 4.4

    二、必须下载的包

    三、配置EF6 provider  .本示例不配置连接字符串,在第四步代码中有设置。

    <configSections>
            <section name="entityFramework"
                     type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            
        </configSections>
        <entityFramework>    
            <providers>
                <provider invariantName="System.Data.SqlServerCe.4.0"
                          type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
            </providers>
        </entityFramework>

    四.Coding~~因为上面配置中没指定ef的默认连接工厂,所以下面使用sqlce的连接工厂创建连接

     1 using System;
     2 using System.Data.Entity;
     3 using System.Data.Entity.Infrastructure;
     4 
     5 namespace org.MvcApp.Models
     6 {
     7     public class mydb:DbContext
     8     {
     9         //fasle表示在释放context时不释放连接。
    10         private static bool connclose=false;
    11         //指定sqlce的provider名,以区别其它版本.注意跟上面配置的名字一致
    12         private static string provider="System.Data.SqlServerCe.4.0";
    13         //指定连接名。名称中如果含有“=”则视为完整连接字符串。否则视为数据库名。
    14         private static string conn="mydb";//将生成mydb.sdf
    15         public mydb():base(new SqlCeConnectionFactory(provider).CreateConnection(conn),connclose)
    16         {
    17         }
    18         
    19         public DbSet<user> users{get;set;}
    20     }
    21 }
    using System;
    
    namespace org.MvcApp.Models
    {
        public class user
        {
            public int ID{get;set;}
            public string Name{get;set;}
        }
    }

    五、调用(略~~~)@@“

    总结:原来EF6的provider还挺多的。

    参考过的资料:

    http://entityframework.codeplex.com/documentation

  • 相关阅读:
    nmap 快速扫描所有端口
    cdh ntpdate 问题
    看22是不是被玻璃破解
    lucas定理
    HDU1398--Square Coins(母函数)
    【转】HDU1028
    【转】母函数(Generating function)详解 — TankyWoo(红色字体为批注)
    HDU--1085--Holding Bin-Laden Captive!(母函数)
    HDU2588--GCD(欧拉函数)
    【转】扩展欧几里德
  • 原文地址:https://www.cnblogs.com/loxen/p/3574939.html
Copyright © 2011-2022 走看看