zoukankan      html  css  js  c++  java
  • MVC+EF

          当初系统使用MVC +linq to entities外加数据模型.edmx也就是db first,但是实际维护模型文件太耗时间,后剔除了模型文件仅保留EF所必须的文件,一样可以达到效果(code first)。现记录修改过程如下。

    1.新建需要的各个实体类  

    例如:shop_order_info.cs shop_goods.cs

       

    2.新建模型上下文类dbContext:        

     1 namespace Xinminghui.Entity.ReturnGoods
     2 {
     3     using System;
     4     using System.Data.Entity;
     5     using System.Data.Entity.Infrastructure;
     6     using System.Data.Entity.ModelConfiguration.Conventions;
     7     
     8     public partial class mysql_shopEntities : DbContext
     9     {
    10         public mysql_shopEntities()
    11             : base("name=mysql_shopEntities")
    12         {
    13             this.Database.Initialize(false);
    14         }
    15     
    16         protected override void OnModelCreating(DbModelBuilder modelBuilder)
    17         {
    18             modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    19             //throw new UnintentionalCodeFirstException();
    20         }    
    27         public DbSet<shop_order_info> shop_order_info { get; set; }
    29         public DbSet<shop_goods> shop_goods { get; set; }
    33     }
    34 }

    3.添加配置文件连接串

      <connectionStrings>
        <add name="mysql_shopEntities" connectionString="Data Source=IP;Initial Catalog=mysql_shop;user id=***;password=123456;" providerName="MySql.Data.MySqlClient" />
      </connectionStrings>

    接下来可以正常使用,以后数据库表更改可以直接修改对应实体类,着实大大提高了工作效率。

    另各项目引用情况如图示(数据库使用MySql)

    学无先后,达者为师
  • 相关阅读:
    Python采用struct处理二进制
    OVS处理upcall流程分析
    mybatis在CRUD
    leetcode先刷_Valid Sudoku
    [TS] Implement a doubly linked list in TypeScript
    [TS] Implement a singly linked list in TypeScript
    [Python] The get() method on Python dicts and its "default" arg
    [Javascript AST] 4. Continue: Report ESLint error
    [RxJS] Learn How To Use RxJS 5.5 Beta 2
    [NPM] Update published npm packages using np
  • 原文地址:https://www.cnblogs.com/seanchang/p/6593597.html
Copyright © 2011-2022 走看看