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

  • 相关阅读:
    Tree(未解决。。。)
    Fractal(递归,好题)
    Scrambled Polygon(凸多边形,斜率)
    ZYB's Game(博弈)
    Dancing Stars on Me(判断正多边形)
    Hidden String(深搜)
    1043
    TEX Quotes(字符串,水)
    Candy Sharing Game(模拟搜索)
    hpu校赛--雪人的高度(离散化线段树)
  • 原文地址:https://www.cnblogs.com/loxen/p/3574939.html
Copyright © 2011-2022 走看看