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. Android开发之使用sqlite3工具操作数据库的两种方式

    使用 sqlite3 工具操作数据库的两种方式 请尊重他人的劳动成果,转载请注明出处:Android开发之使用sqlite3工具操作数据库的两种方式 http://blog.csdn.net/feng ...

  2. java 定位工具

    #查看JVM所有进程及启动类信息以及PID jps -mlvV #查看JVM运行各种状态信息,包括GC,类加载,堆内存信息,jit编译信息等jstat -gcutil <PID> (堆内存 ...

  3. Android:解决Gradle DSL method not found: 'runProguard()' 问题

    将Android Studio升级至最新版(1.0 RC 4)之后,运行项目时出现问题: Gradle DSL method not found: 'runProguard()' 从字面就能看出来,出 ...

  4. POJ1061 青蛙的约会 exgcd

    这个题虽然很简单,但是有一个比较坑的地方,就是gcd不一定是1,有可能是别的数.所以不能return 1,而是return a; 题干: Description 两只青蛙在网上相识了,它们聊得很开心, ...

  5. bzoj2427 [HAOI2010]软件安装——缩点+树形DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2427 今天的考试题...好不容易一次写对了树形DP,却没发现有环的情况... 发现自己 ta ...

  6. IDEA Spark Streaming 操作(套接字流)-----make socket数据源

    import java.io.PrintWriter import java.net.ServerSocket import scala.io.Source object DStream_makeSo ...

  7. Python的包管理工具easy_install, setuptools, pip,distribute介绍

    1.相互之间的关联 easy_install, setuptools, pip,distribute,这几个工具的联系,如下图: 可以看到distribute是setuptools的取代,pip是ea ...

  8. codevs地鼠游戏(贪心)

    1052 地鼠游戏  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description 王钢是一名学习成绩优异的学生,在平时的学习中,他 ...

  9. [Swift通天遁地]三、手势与图表-(5)创建带有标题、图例、坐标轴的柱形图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  10. oracle 误删数据

    insert into hr.job_history select * from hr.job_history as of timestamp to_timestamp('2007-07-23 10: ...