Adding the token entity

From Solution Explorer, right-click on the /Data/Models/ folder and add a new Token.ts C# class file, filling it with the following content:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace TestMakerFreeWebApp.Data
{
public class Token
{
#region Constructor
public Token()
{

}
#endregion

#region Properties
[Key]
[Required]
public int Id { get; set; }

[Required]
public string ClientId { get; set; }

[Required]
public string Value { get; set; }

public int Type { get; set; }

[Required]
public string UserId { get; set; }

[Required]
public DateTime CreatedDate { get; set; }
#endregion

#region Lazy-Load Properties
/// <summary>
/// The user related to this token
/// </summary>
[ForeignKey("UserId")]
public virtual ApplicationUser User { get; set; }
#endregion
}
}

There's nothing new here, just the minimum amount of properties to store the relevant information about the token: the ClientId, where it comes from, its Type(we'll use a value of zero for refresh tokens), its Value, the UserId it was issued to, and the creation date.

Last but not least, we also implemented the User property to take advantage of the EF Core Lazy-Load feature, just like we did with the other entities back in Chapter 4, Data Model with Entity Framework Core. This will require updating the user entity as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.11