Frage

All,

I have read this article: How AspNet Identity with my model where the ApplicationUser has an additing property of

public int AddressId { get; set; }

that is a new property on the ApplicationUser.

But what I am wondering is what if I have a custom entity of my own and I want it to have a property that relates to the Application user:

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

    public ApplicationUser CurrentlyBorrowedBy { get; set; }
}

or

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

    public Guid CurrentlyBorrowedBy { get; set; }
}

The reason I might want to do this is so I can call a method like GetAllBooksBorrowedForUser(userid) for example.

Do I set the properties type to ApplicationUser as show above

or

use a Guid because the DataType of the Id on ApplicationUser is a Guid

or

is this the completely wrong way to do it?

All suggestions welcome.

Note: this is just psuedo code as I just want an understanding of this before I dive into my project.

thanks

Russ

War es hilfreich?

Lösung

From what I know, it should be:


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

Where the ApplicationUser instance allows you to easily navigate

Andere Tipps

All,

Of course after finishing writing my question I found the answer right in front of me.

The sample and blog post written by pranav rastogi here:

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

explains how do do what I am talking about.

Still, feel tree to comment as there is more than one way to skin a cat.

thanks Russ

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top