C
C#ā€¢14mo ago
Carly.TeamSail

ā” EntityFramework - Need help setting up/creating my first VS Community .NET 2.1 Project

Im using VS 2019. Usually I use VS Code, because I only use C# for Unity coding. I created a Postgresql database container using Docker, filled it up with some tables using a GUI software(DbGate, irrelevant for this question). I have a Unity Project and I have the Database setup. Next I need to create a new VS Solution/Project in order to use the EntityFramework, I think? I think I need to create a .dll, so that I can use C# code to communicate between Server and DB only and add new entries to the created tables or GET/SELECT entries from the DB that I can then use on the Server/send to Clients. I have never created a pure C# solution/project, as I said I only use VS Code and before that I used VS just to code C# for my Unity projects aswell. I am pretty sure I need the VS solution/project to be .NET 2.1 since thats what Unity uses. Can someone please tell me the steps that I need to take to make this happen? Thank you.
No description
71 Replies
Angius
Angiusā€¢14mo ago
Can't you just add EF Core as a dependency to your Unity project? Also, will the player need to also run the Postgres database in the Docker container locally? I guess it will remain an unsolved mystery
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Are you trolling? The server will connect to the DB, the Client will only connect to the Game Server And I want to keep it in a separate project so I can easily see which plugins im using and update/remove them
Angius
Angiusā€¢14mo ago
No, it's a legitimate concern, I've seen many a person try to connect directly to the database withouyt any API layer
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
I updated the Q
Angius
Angiusā€¢14mo ago
If it's not the case, then sure, create a new class library and add EF Core as a dependency there And add that project as a dependency to your server
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Can you please explain it like im 6 years old And step by step? This is my first rodeo Step 1 open VS
Angius
Angiusā€¢14mo ago
1. Create a new "class library" project targetting .NET Standard 2.0 2. Add Entity Framework Core as a dependency in the Nuget manager You can create the project in the same solution as your server project That will make it easier to reference it, without the need to compile it to a .dll beforehand
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
I clicked this uhhh it says class library i clicked that template How do I do that? Have you used Unity before? It uses UnityHub > New Project > Opens Unity Editor No solution stuff
Angius
Angiusā€¢14mo ago
Yes solution stuff
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
dang it
Angius
Angiusā€¢14mo ago
If it's a C# project, it has .csproj for the project and .sln for the solution
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
u are correct
Angius
Angiusā€¢14mo ago
Find the .sln file and open it in VS2019 Or, well, VS2022 preferably, but whatever We're using an outdated version of C# anyway so it doesn't matter much
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
I can get itif its recommended Because EF Core needs 2022 I think I heard that somewhere i think
Angius
Angiusā€¢14mo ago
It doesn't
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
ok so i stick with 2019 ok?
Angius
Angiusā€¢14mo ago
Yeah, should be fine
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
NuGet? Or make separate project? Inside this one?
Angius
Angiusā€¢14mo ago
uh You opened the solution as a text file, in VS Code
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
shhhiiieeeett
Angius
Angiusā€¢14mo ago
I told you to open it in VS 2019
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
ok sorry 1 sec Here we go here we go
Angius
Angiusā€¢14mo ago
You can right-click this solution now to add a new project to it
No description
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
ok ill try Library class?
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Angius
Angiusā€¢14mo ago
ye
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
I think .Net Standard 2.0? I can also choose 2.1? But I think Unity uses 2.0 by default (I dont know the difference honestly)
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Now I do the Nuget thingie? ? šŸ„°
Angius
Angiusā€¢14mo ago
Yes, 2.0 Nuget package manager should be somewhere in the menus on the toolbar Can't quite remember which menu it is, though
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
epic
Angius
Angiusā€¢14mo ago
You want EF Core And you want NpgSQL if you're using Postgres
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
I got it EntityFrame.Postgresql? I did it again
Angius
Angiusā€¢14mo ago
ye
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Severity Code Description Project File Line Suppression State Error NU1202 Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 supports: - net6.0 (.NETCoreApp,Version=v6.0) - net7.0 (.NETCoreApp,Version=v7.0) Age Of Sail Online Utils C:\Users\Documents\GitHub\Age Of Sail Online Utils\Age Of Sail Online Utils.csproj 1 I need .net 6 or 7?
Angius
Angiusā€¢14mo ago
Ah, well, seems you'll need to install older versions of those packages, yeah Check on nuget.org which version is compatible with Standard 2.0
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
3.1.18? 5.0.0 is .net 2.1 Im asking someone else from the community if they use .NET 2.1 for their MMO project, just to make sure i get the correct/best version
Angius
Angiusā€¢14mo ago
Yeah, asking around would be a good idea I don't work with versions this out of date, so my knowledge on the topic is limited
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
He told me everything is 2.1 (unity) Im opening my unity project now just to make sure but if thats the case I need to remake the utils project and target 2.1?
Angius
Angiusā€¢14mo ago
You can just change it in project properties, no need to recreate the whole project
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
He is correct iuts 2.1 ok cool I think it deleted my Utils project when I opened my unity project inmside unity because its gone So gonna remake it anyway :p Do i need .Design aswell? Microsoft.EntityFrameworkCore.Design I got them all, also the postgres.Design one Just to make sure I guess?
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Angius
Angiusā€¢14mo ago
right-click it, open properties
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Angius
Angiusā€¢14mo ago
It seems to be on 2.1 already, so you're good
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
This is the other guys packages xD
No description
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
But i dont need them all I think, just the DB ones for now to answer this Q we are discussing I got it all
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No description
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
How do I save it, so that Unity will recognize the changes and not delete them again? Just save it? I saved the sln file šŸ¤ž šŸ¤ž
Angius
Angiusā€¢14mo ago
ĀÆ\_(惄)_/ĀÆ You should probably ask on a more Unity-specific server
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Alright, but whats next?
Angius
Angiusā€¢14mo ago
Next, you write your code
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Can i start writing [Schema(my_schema), Table(my_table)] or whatever the real Attributes are?
Angius
Angiusā€¢14mo ago
You read through the EF Core and NpgSQL docs to learn how to set everything up
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
Ok ok
Angius
Angiusā€¢14mo ago
And, sure, you can start from your existing schema
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
I love it
Angius
Angiusā€¢14mo ago
Although it's preferable to just use the code-first workflow instead But you can always just generate the models and stuff from the existing schema, and create any modifications from that point on with code-first
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
So now I can use the namespaces from EF inside my main Unity Proj scripts? Do i need to mess with asmdef files or anything?
Angius
Angiusā€¢14mo ago
You can use it in the project that has the dependency
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
No .dlls? No Building the Utils project?
Angius
Angiusā€¢14mo ago
And you can add that project as a dependency to other projects Then, everything should build at once Yes
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
You lost me Whats my next concrete step please
MODiX
MODiXā€¢14mo ago
Angius
You read through the EF Core and NpgSQL docs to learn how to set everything up
React with āŒ to remove this embed.
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ Thanks for your help and time, I appreciate it!
Angius
Angiusā€¢14mo ago
Anytime Ok
Carly.TeamSail
Carly.TeamSailOPā€¢14mo ago
And I love pepe pepecoffee i love this Channel now
Accord
Accordā€¢14mo 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