Zacząłem uczyć się ASP.NET MVC, a na tym etapie nauki chcę stworzyć prosty blog. Zdecydowałem się użyć ASP.NET MVC i ORM Entity Framework. Prawdopodobnie masz jakieś przydatne linki na ten temat? Najpierw próbowałem zacząć od utworzenia kodu modelu. Mam 3 klasy Post, Użytkownik (użytkownik może być administratorem), Komentarze.Jak używać EF do automatycznego tworzenia bazy danych i repozytorium w ASP.NET MVC?
Potrzebuję pomocy w tworzeniu relacji między modelami baz danych. Mam kod jak to teraz:
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public List<Comment> Comments { get; set; }
public DateTime PublishDate { get; set; }
}
public class User
{
public readonly bool IsAdmin { get; set; }
public string FirstName { get; set; }
public string SecondName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public DateTime DateOfBirthday { get; set; }
public string Country { get; set; }
public string City { get; set; }
public List<Post> Posts { get; set; }
public List<Comment> Comments { get; set; }
}
public class Comment
{
public int CommentId { get; set; }
public string UserName { get; set; }
public string Content { get; set; }
public DateTime PublishDate { get; set; }
}
Są to moje klasy do tworzenia tabel baz danych, ale nie jestem pewien, jak uczynić stosunki jak wiele-do-jednego. Czy to poprawnie zrobić listę komentarzy do postu lub po prostu wpisać int CommentID ?? Nigdy nie korzystałem z bazy danych bardzo głęboko, widziałem tylko kilka lekcji. Czy ktoś może doradzić, w jaki sposób utworzyć repozytorium lub poprawić mój kod modelu? Dziękuję bardzo!
Czy przeczytałeś pierwsze tutoriale kodu? –
+1 - witamy w StackOverflow: o) – Andrew
Dziękuję u Andrew! – BeginerDummy