[英]Use queryable of Owin Users from UserManager and join with another entity
我正在使用ASP.net Identity 2.2,並且希望將我的用戶(可查詢)與另一個實體一起加入。 我的數據庫上下文是這樣的:
public class ApplicationDbContext:IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
:base("DefaultConnection",throwIfV1Schema:false)
{
Configuration.ProxyCreationEnabled = false;
Configuration.LazyLoadingEnabled = false;
}
public DbSet<Class> Class{ get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
我有這樣的BaseController:
public class BaseApiController : ApiController
{
protected ApplicationUserManager AppUserManager
{
get
{
return _appUserManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
}
}
我可以在控制器中像這樣查詢用戶
var users = AppUserManager.Users
但是當我想將表加入該用戶時,出現以下錯誤。
我在api的構造函數中使dbContext為新的。
我有一個小應用程序,不想與DI Containers一起使用。
指定的LINQ表達式包含對與不同上下文關聯的查詢的引用
用另一個表加入用戶的正確方法是什么?
例如,如果您想將User
與Class
一起加入:
var applicationDbContext = HttpContext.GetOwinContext().Get<ApplicationDbContext>();
var query = from user in applicationDbContext.Users
join class in ApplicationDbContext.Class on user.Id equals class.UserId
select new { user, class };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.