C
C#2y ago
RiamuYui

❔ How to migrate a virtual ICollection to a table on my SQL database?

I have my model and it includes ICollections of different models that I would also like to save. I have never used an SQL database before I do not know what data type and structure to use for the virtual ICollections.
12 Replies
FusedQyou
FusedQyou2y ago
I think it's a good idea if you create a basic proof of concept using EntityFramework before you consider migrating In the last picture you seem to create the query yourself but EntityFramework can also do this for you, using migrations the virtual keyword is only required if you have lazy loading In your case Orientation and PowerResults just need a reference back to the project in order to complete the one-to-many relation. If you need a many-to-many, you will need to do some more though. Just remember that EntityFramework is smart enough to create the relation using migrations, if you use that So you don't really need to do all the queries yourself.
RiamuYui
RiamuYui2y ago
In this case I believe it is one to many as just one project will relate to multiple orientations and power results. I have never done this before nor used entity framework so bear with me here, how do I use it to create these migrations for me?
FusedQyou
FusedQyou2y ago
Do you have a DbContext? This basically defines your context and it will create your queries.
RiamuYui
RiamuYui2y ago
RiamuYui
RiamuYui2y ago
work in progress but yes
FusedQyou
FusedQyou2y ago
Tutorial: Get started with EF Core in an ASP.NET MVC web app
This page is the first in a series of tutorials that explain how to build the Contoso University sample EF/MVC app
FusedQyou
FusedQyou2y ago
This explains pretty well how to work with EntityFramework, how relations work
FusedQyou
FusedQyou2y ago
https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations?source=recommendations&view=aspnetcore-7.0 This link kind of explains how migrations work. Maybe you can apply it to your database
Tutorial Part 5, apply migrations to the Contoso University sample
Part 5 of the Contoso University tutorial series. Use the EF Core migrations feature for managing data model changes in an ASP.NET Core MVC app.
FusedQyou
FusedQyou2y ago
EntityFramework is huge and complex. If this migration is for an important project, I would advice you know pretty well how it works, as it works with a lot of complex subjects such as having the ability to track changes, work with a fluent api, many attributes, etcetera It's all really well done though
RiamuYui
RiamuYui2y ago
Okay thank you, I'll see what I can do! And I appreciate it, this is my first and only c# project I've worked on and the rest of it I've managed to figure out but I haven't been able to wrap my head around this part yet so thank you.
FusedQyou
FusedQyou2y ago
No problem, in my opinion they made it really easy to jump into as long as you put your head into it, so I'm sure you'll get used to it
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Default behavior of ComVisible attributeWhile updating a legacy .NET framework application to net6, I ran into a question where I was unable❔ Is there any overview of useful attributes and how to use them?E.g. [Obsolete] or for example where a method is allowed to be used and so on. Basically basic attri❔ Newtonsoft, count nested propertiesSome time ago I had a nice chat in here where we found a solution to a problem. Namely counting all list that holds 2 values eachI want to have a way to store a dynamic amount of data, where each entry holds a string and an int. ❔ How to close a process's handle?Hey folks, I'm trying to automate something that I've been doing manually through Process Explorer -❔ ObjectListView showing blank rowsHi all. I'm new to C# and making VSTO addins, please bare with me! I'm using the add-in control O❔ NullReferenceException Object reference not set to an instance of an object Billboard.UpdateHello, my name is Zorphix and I'm not so smart at C#. And I'm currently trying to add a billboard sc❔ Blazor Hosted - Client datatable with large datasetI have a table component (using MudBlazor) which accesses the server-side API endpoint and pulls (cu❔ How do I cycle through different observable collections within the same collection view?My current plan is to do something like: ``` List <ObservableCollection<TodoItem>> allTodoItems✅ I'm trying to understand WPF's source code. What is a WeakReferenceWeakReference is a class that probably has applications other than in WPF (in particular, I'm trying