EF 配置
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 配置的更多相关文章
- EF配置模型
配置方法 EF里面的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面,还有 ...
- 从头编写 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部分 ...
- 【转载】从头编写 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 ...
- EF 配置MySQL
添加 mysql dll 引用 WebConfig 配置: 1.先添加connectionstrings,providerName 换成 mysql的 <connectionStrings> ...
- EF 配置实现建表与迁移
通过EF 作为操作数据库的工具有一段时间了,也做了几个相对不大的项目,慢慢的也对EF的使用摸索出来了一些规则,虽然说不是技术难点,但是,我说的是但是,能够提高我们开发效率的棉花糖有时我们还是必须要吃的 ...
- EF 配置多个数据库
1.先创建两个DbContext using System; using System.Data.Common; using System.Data.Entity; using System.Data ...
- EF 配置(SqlServer,Mysql)
DbProvider Mysql <system.data><DbProviderFactories><remove invariant="MySql.Data ...
- vs+mysql+ef配置方法
这次的项目用的是MySQL数据库,但是ADO.NET实体数据模型默认是不支持MySQL数据库的,本文档将介绍如何让VS ADO.NET实体数据模型支持MySQL. 一.安装插件 1.VS插件 mysq ...
- EF里一对一、一对多、多对多关系的配置和级联删除
本章节开始了解EF的各种关系.如果你对EF里实体间的各种关系还不是很熟悉,可以看看我的思路,能帮你更快的理解. I.实体间一对一的关系 添加一个PersonPhoto类,表示用户照片类 /// < ...
随机推荐
- JavaScript初探之——图片移动
在我们打开页面的时候我们看到的大部分页面都是动态的,曾经学习VB的时候要实现一些动态的画面第一个想到的就是用Flash,如今学习了BS的东西,才算是开眼界了,刚刚学习了一个动画的效果,给大家展示一下. ...
- 我所未知的 typeof 现象
一.一些基本使用测试 从上述可以看出: 1.判断一个 变量 是不是对象类型,不能只用 typeof 运算符: 2.它的返回值一直是一个字符串: 3.尽管 typeof null === 'object ...
- HDU 5289 Assignment (二分+区间最值)
[题目链接]click here~~ [题目大意]: 给出一个数列,问当中存在多少连续子序列,子序列的最大值-最小值<k [思路]:枚举数列左端点.然后二分枚举右端点,用ST算法求区间最值.(或 ...
- 自己定义 View 基础和原理
课程背景: 在 Android 提供的系统控件不能满足需求的情况下,往往须要自己开发自己定义 View 来满足需求,可是该怎样下手呢.本课程将带你进入自己定义 View 的开发过程,来了解它的一些原理 ...
- C - Gr-idian MST
Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement On an xy plane, in an ...
- Android横竖屏切换不重新调用onCreate()
再次感叹Android的碎片化!!!! 设置AndroidManifest.xml中Activity的android:configChanges=”keyboardHidden|orientation ...
- 如何理解Apache License, Version 2.0(整理)
如何理解Apache License, Version 2.0(整理) 问题: 最近看到apache发布了2.0版本的License.而且微软也以此发布了部分源代码.我对OpenSource不是特熟, ...
- Scikit-learn库中的数据预处理:独热编码(二)
在上一篇博客中介绍了数值型数据的预处理但是真实世界的数据集通常都含有分类型变量(categorical value)的特征.当我们讨论分类型数据时,我们不区分其取值是否有序.比如T恤尺寸是有序的,因为 ...
- [CF391E2]Three Trees
https://zybuluo.com/ysner/note/1246822 题面 有三棵树,建两条边让他们相连,最大化所有点对距离之和. \(40pts\ n\leq1000\) \(100pts\ ...
- 洛谷 P3377 模板左偏树
题目:https://www.luogu.org/problemnew/show/P3377 左偏树的模板题: 加深了我对空 merge 的理解: 结构体的编号就是原序列的位置. 代码如下: #inc ...