【问题标题】:ASP.NET Identity - ApplicationUser and my custom models / entitiesASP.NET Identity - ApplicationUser 和我的自定义模型/实体
【发布时间】:2014-03-10 06:33:56
【问题描述】:

全部,

我读过这篇文章: How AspNet Identity with my model 其中 ApplicationUser 的添加属性为

public int AddressId { get; set; }

这是 ApplicationUser 上的一个新属性。

但我想知道的是,如果我有一个 我自己的 自定义实体并且我希望它具有与应用程序用户相关的属性:

public class Book
{
    public int Id { get; set; }
    public string Title { get; set; }

    public ApplicationUser CurrentlyBorrowedBy { get; set; }
}

public class Book
{
    public int Id { get; set; }
    public string Title { get; set; }

    public Guid CurrentlyBorrowedBy { get; set; }
}

我可能想要这样做的原因是我可以调用像 GetAllBooksBorrowedForUser(userid) 这样的方法。

我是否将属性类型设置为 ApplicationUser,如上所示

使用 Guid,因为 ApplicationUser 上的 Id 的 DataType 是 Guid

这是完全错误的做法吗?

欢迎所有建议。

注意:这只是伪代码,因为我只是想在深入了解我的项目之前了解这一点。

谢谢

罗斯

【问题讨论】:

    标签: c# asp.net identity asp.net-mvc-5.1


    【解决方案1】:

    据我所知,应该是:


    public int CurrentlyBorrowedByID { get; set; }
    public virtual ApplicationUser CurrentlyBorrowedBy { get; set; }
    

    ApplicationUser 实例可让您轻松导航的位置

    【讨论】:

      【解决方案2】:

      全部,

      当然,写完我的问题后,我就在眼前找到了答案。

      pranav rastogi 在此处撰写的示例和博客文章:

      http://blogs.msdn.com/b/webdev/archive/2013/10/20/building-a-simple-todo-application-with-asp-net-identity-and-associating-users-with-todoes.aspx

      解释我在说什么。

      不过,请随意评论,因为给猫剥皮的方法不止一种。

      谢谢 拉斯

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-19
        • 2014-04-30
        • 1970-01-01
        • 1970-01-01
        • 2013-11-18
        • 2019-12-11
        • 1970-01-01
        • 2022-01-12
        相关资源
        最近更新 更多