Firas Maswadeh February 2016

How to add a tag class to database using Migrations

I Just want to create these classes and then use the migration to update my database . My question is :

How to make PostTagMap class ? and here is the photo of the classes relation ..

Classes Picture

public class Post
{
    public virtual int Id
    { get; set; }

    public virtual string Title
    { get; set; }

    public virtual string ShortDescription
    { get; set; }

    public virtual string Description
    { get; set; }

    public virtual string Meta
    { get; set; }

    public virtual string UrlSlug
    { get; set; }

    public virtual bool Published
    { get; set; }

    public virtual DateTime PostedOn
    { get; set; }

    public virtual DateTime? Modified
    { get; set; }

    public virtual Category Category
    { get; set; }

    public virtual IList<Tag> Tags
    { get; set; }
}

and here is the tag class :

 public class Tag
{
    public virtual int Id
    { get; set; }

    public virtual string Name
    { get; set; }

    public virtual string UrlSlug
    { get; set; }

    public virtual string Description
    { get; set; }

    public virtual IList<Post> Posts
    { get; set; }
}

Answers


Bon Macalindong February 2016

You really don't need to create a PostTagMap class, the many many relationship is already handled by your navigation Properties in your case public virtual IList<Tag> Tags { get; set; } for Post class and public virtual IList<Post> Posts { get; set; } for Tag Class. This will be handled once you run update-database

Post Status

Asked in February 2016
Viewed 3,186 times
Voted 12
Answered 1 times

Search




Leave an answer