puzzy.x
puzzy.x

Reputation: 61

How to make list property in .net core and use it inside another table without Id?

I have to make a model in .Net Core and output of that model has to be something like this:

{
  "tags": [
     "angularjs",
     "python"
   ]
 }

I assume it's kind of unusual property for me since I am new in C#. After that, I need to use that model (those tags) in Posts model.

My Posts.cs model:

    public class Posts
{
    [Key]
    public int slug { get; set; }
    [Required]
    [Column(TypeName = "nvarchar(100)")]
    public string title { get; set; }
    [Required]
    [Column(TypeName = "nvarchar(50)")]
    public string description { get; set; }
    [Required]
    [Column(TypeName = "nvarchar(100)")]
    public string body { get; set; }
    // I want to get tagList from another model named Tags.cs, but it is empty right now, since I don't know how to create property for list
    [Required]
    [Column(TypeName = "datetime")]
    public DateTime createdAt { get; set; }
    [Required]
    [Column(TypeName = "datetime")]
    public DateTime updatedAt { get; set; }
}

How can I achieve that? Any idea? Thank you in advance.

Upvotes: 1

Views: 345

Answers (1)

Cəfərov Murad
Cəfərov Murad

Reputation: 70

You can use navigation property.

public List<string> Tags {get; set;}

Upvotes: 2

Related Questions