Last post Mar 17, 2017 12:41 PM by PatriceSc
Mar 17, 2017 09:04 AM|Barsik_The_CaT|LINK
I need to write a small blog (just a task at university). It involves a page that shows a single blog post and all comments for it. With PHP and SQL it would be a no-brainer, but I don't quite understand how would that work with Entity Framework. Should
I make it so each blog post has a field that is a list of IDs of related comments, or should I make every ID have a field that points to a related blog post?
Mar 17, 2017 09:17 AM|PatriceSc|LINK
Using EF shouldn't change anything to your database design. Usually you just don't have multivalued fields. Instead each "child" element is related to its parent using the ID for the parent. So here more likely you would have each comment having the ID for
the blog post it belongs to (not sure if you want to track comments answered to previous comments ?)
On the EF side it will be seen as a collection of related comments for each blog post.
Mar 17, 2017 12:30 PM|Barsik_The_CaT|LINK
Ehm, is there a way to make Entity Framework code generation more predictable? If I do my model the 'code-first' way, it does not necessarily create what I want. If I try the 'db-first' approach and make EF generate model classes - it is even worse.
Mar 17, 2017 12:41 PM|PatriceSc|LINK
Try perhaps to start from https://msdn.microsoft.com/en-us/library/jj591583(v=vs.113).aspx which uses blogs, posts and comments. It should generate the same database for both
of us and then we would need to know how it differs from what you expect.