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类,表示用户照片类 /// < ...
随机推荐
- MySQL计算字段
计算字段 数据库中存放的表是按列存放,可是有时客户机想获得的信息是若干列之间的组合,或者求和的值.这个组合或者求和的动作能够放在客户机应用程序来做.可是在数据库中实现更为高效. 这个新计算出来的结果就 ...
- python-pexpect_02ssh
#!/usr/bin/env python """ This runs a command on a remote host using SSH. At the prom ...
- vijos - P1302连续自然数和 (公式推导 + python)
P1302连续自然数和 Accepted 标签:[显示标签] 描写叙述 对一个给定的自然数M,求出所有的连续的自然数段(连续个数大于1).这些连续的自然数段中的所有数之和为M. 样例:1998+199 ...
- c++中读写文件操作
读写文件这个,不常用,每次用的时候都会百度一下,每次写法还都不一样,所有总是记混.今天利用点时间总结下之前工程中用过的.以后就安照这种方法写了. 搞acmicpc的时候喜欢用freopen(),这个是 ...
- 关于EditText的android:maxLength属性的注意事项
一直以为在xml布局文件中对EditText添加 android:maxLength="30";属性是控制EditText字符数的.想当然的以为一个中文占2个字符,一个英文占1个字 ...
- ASP.NET MVC 4 Content Map
https://msdn.microsoft.com/en-us/library/gg416514(v=vs.108).aspx The Model-View-Controller (MVC) pat ...
- Bing Maps进阶系列六:使用Silverlight剪切(Clip)特性实现Bing Maps的迷你小地图
Bing Maps进阶系列六:使用Silverlight剪切(Clip)特性实现Bing Maps的迷你小地图 Bing Maps Silverlight Control虽然为我们提供了简洁.方面的开 ...
- 【POJ 1845】 Sumdiv
[题目链接] 点击打开链接 [算法] 不妨先将A分解质因数 A = p1^q1p2^p2p3^p3..pn^qn 那么,A^B = p1^q1Bp2^q2B...pn^qnB 根据约数和定理,A^B的 ...
- 洛谷P2303 [SDOi2012]Longge的问题
题目背景 SDOi2012 题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). ...
- element-ui table 页面加载时,动态渲染后台传过来的数据(springmvc)
jsp页面 <%@ page contentType="text/html;charset=UTF-8" language="java" %> &l ...