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. erlang二进制数据垃圾回收机制

    erlang二进制数据在内存中有两种存在形式,当数据大小不到 64 bytes,就直接存在进程堆内.假设超过了64 bytes.就被保存到进程外的共享堆里,能够给节点内全部进程共享. erlang有两 ...

  2. leetcode_Product of Array Except Self

    描写叙述: Given an array of n integers where n > 1, nums, return an array output such that output[i]  ...

  3. android高速开发框架xUtils

    xUtils简单介绍 xUtils 包括了非常多有用的android工具. xUtils 支持大文件上传,更全面的http请求协议支持(10种谓词).拥有更加灵活的ORM,很多其它的事件注解支持且不受 ...

  4. LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  5. LeetCode 141. Linked List Cycle (链表循环)

    Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...

  6. phonegap运行原理

    用phonegap(现在名为cordova)来开发手机应用,给人的感觉,就是写了一些HTML5的网页,加上javascript,打包安装在手机上,然后就可以运行了,并且还能访问手机的各种功能和硬件,太 ...

  7. C 符号表导出

    编译符号表导出示例: 使用GCC编译链接参数--version-script 控制动态符号表,如想 使用链接参数 --retain-symbols-file 控制静态符号表,--version-scr ...

  8. POJ 2610:Dog & Gopher

    Dog & Gopher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4142   Accepted: 1747 ...

  9. 云栖社区> > 正文 永久免费SSL安全证书Letsencrypt安装使用方法

    ./letsencrypt-auto certonly --standalone --email admin@thing.com -d thing.com -d www.thing.com

  10. PCB SQL Server 代码创建DbLink

    代码如下: ) ) ) ) ) SET @serverName = 'DbLinkName' --db链接名 SET @ip = '120.79.36.65' --需连接服务器的IP SET @dbN ...