小编NaN*_*erd的帖子

来自TPH继承中的子类型的LINQ .Include()属性

我在Entity Framework中使用每层次表(TPH)继承.现在我希望得到一个列表 - 在这个例子中 - 部门可以是子类型.我希望集合中的项目包含自己的自定义属性,而不仅仅是基本模型的属性.

我怎样才能做到这一点?

public class Department
{
    public Department()
    {
        DepartmentType = this.GetType.Name;
    }
    public int Id {get; set;}
    public string DepartmentType {get; set;}
}

public class Finance : Department
{
    public virtual Manager Manager {get; set;}
}

public class Sports : Department
{
    public virtual Coach Coach {get; set;}
}


// This obviously crashes instantly
// How can I include Manager if type is Finance and Coach if type is Sports?
context.Departments
        .Include(c …
Run Code Online (Sandbox Code Playgroud)

c# linq inheritance json

7
推荐指数
1
解决办法
1123
查看次数

在 WEB API 2 中使用 ApplicationSignInManager

我正在尝试通过 Web API 2 登录。我所做的是从 MVC 5.2 的 AccountController 复制一些代码,但是当我运行此代码时,ApplicationSignInManager 是null并且它抛出异常。

我在 Github 或 ASP.NET 上找不到任何示例项目。

这是我的自定义 UserController Web API。

[RoutePrefix("api/users")]
public class UserController : ApiController
{

    ... // Truncated for brevity

    [Route("login")]
    [HttpPost]
    public HttpResponseMessage Login(LoginViewModel model)
    {
        if (!ModelState.IsValid)
        {
            return new HttpResponseMessage(HttpStatusCode.Forbidden);
        }
        var signinManager = Request.GetOwinContext().Get<ApplicationSignInManager>();

        // This doesn't count login failures towards account lockout
        // To enable password failures to trigger account lockout, change to shouldLockout: true
        SignInStatus result = 
            signinManager.PasswordSignIn(model.Email, model.Password, model.RememberMe, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

5
推荐指数
0
解决办法
6050
查看次数

标签 统计

c# ×2

asp.net-mvc ×1

inheritance ×1

json ×1

linq ×1