????1.??????????
????1.2??
?????????????/????????????????????????????????????????

????????????????????????????????·????
????1.2????
????????????ó???????????????????MS???ASP.NET 5????????beta1???У?????XUnit.KRunner??beta2???????????????????
???????????ò???EF?????????????????????д????????????????????????壨?????????????????????????????????????????????????Fluent API??????????????????β????????????????????????????????????????????????Щ????????????????????????????£??????????塣
????????????????????????????仰?????????????????????????????????????

 

using System.ComponentModel.DataAnnotations;
namespace BlogASPNET5.Entity.Bases
{
/// <summary>
/// ??????
/// </summary>
/// <typeparam name="T">????????</typeparam>
public class EntityBase<T>
{
[Key]
public T Id { get; set; }
//??????????
//??????
//?а汾
}
}

???????EF??????????????????Guid????????????Id??????+Id???????Сд?????????????Key??????????????Guid????????????????????????????????????????????????????????
?????????????Account????????壺

 

using BlogASPNET5.Entity.Bases;
using System.Collections.Generic;
namespace BlogASPNET5.Entity.Accounts
{
/// <summary>
/// ??????
/// </summary>
public class Role :EntityBase<int>
{
public string Name { get; set; }
public string Description { get; set; }
/// <summary>
/// ????????  ?????????Redis???????????????
/// </summary>
public ICollection<User> Users { get; set; }
}
}
Account?????????壺
using BlogASPNET5.Entity.Bases;
namespace BlogASPNET5.Entity.Accounts
{
public class User : EntityBase<int>
{
public string Name { get; set; }
public string Password { get; set; }
public Gender Gender { get; set; }
/// <summary>
/// ???Id ???
/// </summary>
public int RoleId { get; set; }
/// <summary>
/// ????????
/// </summary>
public Role Role { get; set; }
}
/// <summary>
/// ??? ???????
/// </summary>
public enum Gender { man?? woman }
}

???????EF7??????????????????????м???????????????????????????????Redis??????????????????
??????????EF????????????????????????EF????????????

 

using BlogASPNET5.Entity.Accounts;
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Metadata;
namespace BlogASPNET5.Repository.Contexts
{
public class EFContext :DbContext
{
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer("Server=.;Database=TestDB;UID=sa;PWD=123456;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//???????????????
modelBuilder.Entity<User>().ManyToOne(r => r.Role?? u => u.Users).ForeignKey(f => f.RoleId);
}
}
}