EF之实体拆分
来源:互联网 发布:淘宝上怎么开企业店铺 编辑:程序博客网 时间:2024/04/30 17:57
实体拆分:将一个实体类拆分成多张表。
例:Code First模式下将实体User拆分为Users表和UserInfo表。
using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.Data.Entity;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp{ class Program { static void Main(string[] args) { using (var db = new DemoContext()) { User user = new User { UserName = "Tony", Password = "3.1415926", RealName = "吴先森", Age = 25, Address = "BJ" }; db.Users.Add(user); db.SaveChanges(); IEnumerable<User> users = db.Users.AsEnumerable<User>(); foreach (var u in users) { Console.WriteLine("UserName:{0}, Password:{1}.", u.UserName, u.Password); } } Console.ReadKey(); } } //DbContent public class DemoContext : DbContext { public DemoContext() : base("name=DemoContext") { } public DbSet<User> Users { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { //one entity to many tables modelBuilder.Entity<User>() .Map(m => { m.Properties(t => new { t.Id, t.UserName, t.Password }); m.ToTable("Users"); }) .Map(m => { m.Properties(t => new { t.Id, t.RealName, t.Age, t.Address }); m.ToTable("UserInfo"); }); base.OnModelCreating(modelBuilder); } } //Entity public class User { [Key] public int Id { get; set; } public string UserName { get; set; } public string Password { get; set; } public string RealName { get; set; } public int Age { get; set; } public string Address { get; set; } }}
0 0
- EF之实体拆分
- EF之表拆分
- EF之ModelFirst实体先行
- EF之缺少映射实体
- MVC3教程之实体模型和EF CodeFirst
- MVC3教程之实体模型和EF CodeFirst
- EF 加载相关实体
- EF----实体框架集合
- EF实体框架学习
- 【EF 1】EF实体框架 原理+实例
- EF-实体对象建立Dome
- EF实体框架初了解
- EF实体类型 添加AddObject
- 【EF系列】ModelFirst实体优先
- EF实体对象变动跟踪
- EntityFramework 实体拆分和表拆分
- fineui经验积累1之EF实体关系对应对应错误
- EF实体数据无法修改之 this .Configuration.AutoDetectChangesEnabled = true ; 要看的链接
- fdsafdsafds
- iOS自带的二维码扫描功能
- MikuMikuDance V7.39 汉化版
- 字符驱动程序 (国嵌笔记)
- 机器学习—朴素贝叶斯进行文本分类
- EF之实体拆分
- UNIX环境编程 学习1
- 什么是AOP?
- Android生命周期(三)
- iOS中的cookie的使用
- 人人,金山西山居,腾讯互娱,微信,网易游戏offer及面经
- IOCTL 高级字符设备驱动程序(国嵌笔记)
- PlSQL Developer 使用过期问题
- 类加载过程