EF Core Fluent API
2021-06-28 13:06
标签:where oid base ima weixin protected ase 核心 技术分享 先安装 Install-Package MySql.Data.EntityFrameworkCore 创建3个表 创建类 编写DbContext,ef core的DbContext等EF的核心类在using Microsoft.EntityFrameworkCore; 运行: 链接:EF Fluent API https://www.cnblogs.com/tangge/p/9831957.html EF Core Fluent API 标签:where oid base ima weixin protected ase 核心 技术分享 原文地址:https://www.cnblogs.com/tangge/p/10041692.html public class Role
{
public long Id { get; set; }
public string Name { get; set; }
}
public class User
{
public long Id { get; set; }
public string Name { get; set; }
}
public class UserRoleRelation
{
public long Id { get; set; }
public long UserId { get; set; }
public long RoleId { get; set; }
public User User { get; set; }
public Role Role { get; set; }
}
public class MyDbContext : DbContext
{
public DbSet
using (MyDbContext ctx = new MyDbContext())
{
var user = ctx.Users.First();
long userId = user.Id;
var relactions = ctx.UserRoleRelations.Include(e => e.Role)
.Where(r => r.UserId == userId);
foreach (var relation in relactions)
{
Console.WriteLine(relation.Role.Name);
}
}
文章标题:EF Core Fluent API
文章链接:http://soscw.com/index.php/essay/98898.html