???ASP.NET 5????????????
???????????? ???????[ 2015/1/27 17:44:58 ] ?????????????
????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);
}
}
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11