Base solution for your next web application
Open Closed

Accessing User Entity from code #1444


User avatar
0
jamsecgmbh created

Dear ASP.NET Boilerplate Support,

I want to use data from the User table in my code - how can I make it accessible? Do I need to create an IDbSet manually in the DbContext class?

Thank you very much and best regards Chris

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    How do you want to use User table's data ? User entity is alredy included in DbContet.

    You can get users by UserManager class.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    jamsecgmbh created

    Thank you!

    How can I create a foreign key pointing to the id of an user in the user table?

    [Table("DbAppTesttable")]
    public class Testtable : FullAuditedEntity<long>, IMustHaveTenant
    {
        // Foreign Key: ID of User
        [ForeignKey("User ...
        ...
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    It should be something like this,

    [ForeignKey("UserId")]
    public virtual User User { get; set; }
    
    public virtual long UserId { get; set; }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)