ApplicationUserと独自に作成した という名前のクラスの間に多対多の関係を持つテーブルを作成しますTopic。ユーザーがトピックに複数回投票できないように、トピックに対するユーザーからの賛成票と反対票を保持するために使用するテーブル。したがって、私の考えは、以下に示すようなテーブルを使用することです (⚿ はテーブルの主キーです)。
╔══════════════════════╦════════════════════╦═════════╦════════════════════════╗
║ UserId ⚿ ║ TopicId ⚿ ║ Vote ║ Time ║
╠══════════════════════╬════════════════════╬═════════╬════════════════════════╣
║ x ║ 1 ║ up ║ 2016/02/02 15:00:00 ║
║ y ║ 2 ║ up ║ 2016/02/01 15:00:00 ║
║ y ║ 1 ║ down ║ 2016/01/01 14:00:00 ║
╚══════════════════════╩════════════════════╩═════════╩════════════════════════╝
↓ ↓ ↓ ↓
Must reference to Must reference to Other information about the vote
the table where the the table where my
users are stored topic are stored
この構造を ID フレームワークを使用してデータベースに移行するにはどうすればよいですか? コードファーストの作業方法も使用します。
以下に、私のTopicクラスと、そのクラスに拡張された他のクラスを示します。クラス内のコードApplictionUserは変更されていません。
public class Topic
{
public int TopicId { get; set; }
public bool Deleted { get; set; }
public string UserId { get; set; }
public ApplicationUser User{ get; set; }
public string Text { get; set; }
public DateTime Creation { get; set; }
public List<Vlag> Flags { get; set; }
public int? BlogId { get; set; }
public Blog Blog { get; set; }
public int? ReactionId { get; set; }
public Reaction Reaction { get; set; }
}
public class Blog: Topic, IVote
{
public int Id { get; set; }
public int CategorieId { get; set; }
public Categorie Categorie { get; set; }
public string Name { get; set; }
public int Down { get; set; }
public int Up { get; set; }
public int CalculateTotal()
{
return Up - Down;
}
}
public class Reactie : Topic, IVote
{
public int Id { get; set; }
public int Down { get; set; }
public int Up{ get; set; }
public Blog OwnerBlog { get; set; }
public int OwnerBlogId { get; set; }
public int CalculateTotal()
{
return Up - Down;
}
}
public interface IVote // used for holding the number of up and down votes for a blog
// or reaction.
{
int Up { get; set; }
int Down { get; set; }
int CalculateTotal();
}