DbContext
    public class ZSZDbContext : DbContext
{
//ILog ILogger 容易混淆
private static ILog log = LogManager.GetLogger(typeof(ZSZDbContext)); public ZSZDbContext() : base("name=connstr")
//name=conn1表示使用连接字符串中名字为conn1的去连接数据库
{
Database.SetInitializer<ZSZDbContext>(null);
this.Database.Log = sql =>
{
log.DebugFormat("EF执行SQL:{0}", sql);
};
} protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
}
public DbSet<AdminUserEntity> AdminUsers { get; set; }
public DbSet<UserEntity> Users { get; set; }
public DbSet<CityEntity> Cities { get; set; }
public DbSet<CommunityEntity> Communities { get; set; }
public DbSet<PermissionEntity> Permissions { get; set; }
public DbSet<RegionEntity> Regions { get; set; }
public DbSet<RoleEntity> Roles { get; set; }
public DbSet<SettingEntity> Settings { get; set; }
public DbSet<AttachmentEntity> Attachments { get; set; }
public DbSet<HouseEntity> Houses { get; set; }
public DbSet<HouseAppointmentEntity> HouseAppointments { get; set; }
public DbSet<IdNameEntity> IdNames { get; set; }
public DbSet<HousePicEntity> HousePics { get; set; }
public DbSet<AdminLogEntity> AdminUserLogs { get; set; }
}
Entity
    public class HouseEntity : BaseEntity
{
public long CommunityId { get; set; }
public virtual CommunityEntity Community { get; set; }
public long RoomTypeId { get; set; }
public virtual IdNameEntity RoomType { get; set; }
public string Address { get; set; }
public int MonthRent { get; set; }
public long StatusId { get; set; }
public virtual IdNameEntity Status { get; set; }
public decimal Area { get; set; }
public long DecorateStatusId { get; set; }
public virtual IdNameEntity DecorateStatus { get; set; }
public int TotalFloorCount { get; set; }
public int FloorIndex { get; set; }
public long TypeId { get; set; }
public virtual IdNameEntity Type { get; set; }
public string Direction { get; set; }
public DateTime LookableDateTime { get; set; }
public DateTime CheckInDateTime { get; set; }
public string OwnerName { get; set; }
public string OwnerPhoneNum { get; set; }
public string Description { get; set; } public virtual ICollection<AttachmentEntity> Attachments { get; set; } = new List<AttachmentEntity>();
public virtual ICollection<HousePicEntity> HousePics { get; set; } = new List<HousePicEntity>();
}
Config
    class HouseConfig : EntityTypeConfiguration<HouseEntity>
{
public HouseConfig()
{
ToTable("T_Houses");
HasRequired(h => h.Community).WithMany().HasForeignKey(h => h.CommunityId).WillCascadeOnDelete(false);
HasRequired(h => h.RoomType).WithMany().HasForeignKey(h => h.RoomTypeId).WillCascadeOnDelete(false);
HasRequired(h => h.Status).WithMany().HasForeignKey(h => h.StatusId).WillCascadeOnDelete(false);
HasRequired(h => h.DecorateStatus).WithMany().HasForeignKey(h => h.DecorateStatusId).WillCascadeOnDelete(false);
HasRequired(h => h.Type).WithMany().HasForeignKey(h => h.TypeId).WillCascadeOnDelete(false);
Property(h => h.Address).IsRequired().HasMaxLength();
Property(h => h.Description).IsOptional();
Property(h => h.Direction).IsRequired().HasMaxLength();
Property(h => h.OwnerName).IsRequired().HasMaxLength();
Property(h => h.OwnerPhoneNum).IsRequired().HasMaxLength().IsUnicode(false);
}
}

EF 配置的更多相关文章

  1. EF配置模型

    配置方法 EF里面的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面,还有 ...

  2. 从头编写 asp.net core 2.0 web api 基础框架 (4) EF配置

    第1部分:http://www.cnblogs.com/cgzl/p/7637250.html 第2部分:http://www.cnblogs.com/cgzl/p/7640077.html 第3部分 ...

  3. 【转载】从头编写 asp.net core 2.0 web api 基础框架 (4) EF配置

    Github源码地址:https://github.com/solenovex/Building-asp.net-core-2-web-api-starter-template-from-scratc ...

  4. EF 配置MySQL

    添加 mysql dll 引用 WebConfig 配置: 1.先添加connectionstrings,providerName 换成 mysql的 <connectionStrings> ...

  5. EF 配置实现建表与迁移

    通过EF 作为操作数据库的工具有一段时间了,也做了几个相对不大的项目,慢慢的也对EF的使用摸索出来了一些规则,虽然说不是技术难点,但是,我说的是但是,能够提高我们开发效率的棉花糖有时我们还是必须要吃的 ...

  6. EF 配置多个数据库

    1.先创建两个DbContext using System; using System.Data.Common; using System.Data.Entity; using System.Data ...

  7. EF 配置(SqlServer,Mysql)

    DbProvider Mysql <system.data><DbProviderFactories><remove invariant="MySql.Data ...

  8. vs+mysql+ef配置方法

    这次的项目用的是MySQL数据库,但是ADO.NET实体数据模型默认是不支持MySQL数据库的,本文档将介绍如何让VS ADO.NET实体数据模型支持MySQL. 一.安装插件 1.VS插件 mysq ...

  9. EF里一对一、一对多、多对多关系的配置和级联删除

    本章节开始了解EF的各种关系.如果你对EF里实体间的各种关系还不是很熟悉,可以看看我的思路,能帮你更快的理解. I.实体间一对一的关系 添加一个PersonPhoto类,表示用户照片类 /// < ...

随机推荐

  1. Andriod实现刮刮卡的效果

    思想: 将一个View设计成多层,内层(包含中奖信息)和外层(用于刮奖),外层的图层用Canvas与一个Bitmap关联,用这个关联的Bitmap来处理手势的滑动.类似于刮奖的动作. 使用paint. ...

  2. 数据库数据在Java占用内存简单估算

    数据库数据在Java占用内存简单估算 结论: 1.数据库记录放在JAVA里,用对象(ORM一般的处理方式)须要4倍左右的内存空间.用HashMap这样的KV保存须要10倍空间; 2.假设你主要数据是t ...

  3. VC中CString和WPARAM之间的相互转换

    在传递自己定义消息的过程中.须要转换CString 变量. 在发送消息端使用例如以下方法: SendMessage(WM_MESSAG_MINE,0,(LPARAM)strVal.AllocSysSt ...

  4. coffeescript的上下文

    CoffeeScript代码中,变量,甚至函数前面有时会带上一个@符号,那么翻译到 javascript里,就是 "this." 这就涉及到运行过程中的上下文. 这个this指什么 ...

  5. WPF学习笔记:ComboBox的数据绑定

    UI <UserControl x:Class="UnitViews.UserMeUV" xmlns="http://schemas.microsoft.com/w ...

  6. linux C函数之strdup函数分析【转】

    本文转载自:http://blog.csdn.net/tigerjibo/article/details/12784823 linux C函数之strdup函数分析 一.函数分析 1.函数原型: #i ...

  7. WebSocket握手总结

    网址:http://blog.csdn.net/edwingu/article/details/44040961 WebSocket protocol 是HTML5一种新的协议.它实现了浏览器与服务器 ...

  8. explain 详解 (转)

    原文:http://blog.csdn.net/zhuxineli/article/details/14455029 explain显示了MySQL如何使用索引来处理select语句以及连接表.可以帮 ...

  9. C语言作用于修饰符

    之前就遇到了坑,莫名其妙报错.   总结下: extern   声明在其他文件里 static     仅当前文件可见

  10. Gym - 101982B 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) B. Coprime Integers Mobius+容斥 ab间gcd(x,y)=1的对数

    题面 题意:给你 abcd(1e7),求a<=x<=b,c<=y<=d的,gcd(x,y)=1的数量 题解:经典题目,求从1的到n中选x,从1到m中选y的,gcd(x,y)=k ...