zoukankan      html  css  js  c++  java
  • EF 7.0 Beta8 实现简单Unit Of Work 模式

    一、使用Database First模式

    注意:目前的最新的Beta8采用如下方式配置数据库连接 ```csharp protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseSqlServer(@"数据库连接字符串"); } ```

    二、定义与数据库表对应实体类

    ```csharp public clas YourEntity { public int Id; .... } ```

    三、映射实体类到数据库表

    ```csharp protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .ToTable("uc_Users") .HasKey(x => x.UserId); } ```

    四、实现简易的Unit Of Work模式

    ```csharp public IQueryable SetEntity() where T : class { return Set(); }

    // 在ef6中可以使用EntityFramework.Extended提供的UpdateAsync来实现指定字段更新,ef7暂时不知道如何实现
    public async Task UpdateAsync(T entity) where T : class
    {
    Set().Update(entity);
    return await SaveChangesAsync() > 0;
    }

  • 相关阅读:
    倒计时2(小于0时的格式)
    日期 Date()
    倒计时5(超过时间为0:0:0)
    倒计时4
    倒计时3
    Lucene_solr
    Solr与tomcat搭建(搭建好)
    SSM(Spring-SpringMvc-Mybatis)练习
    SpringMvc
    Mybatis(使用)与Spring整合
  • 原文地址:https://www.cnblogs.com/jackFloyd/p/4956247.html
Copyright © 2011-2022 走看看