ā 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.
71 Replies
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
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
No, it's a legitimate concern, I've seen many a person try to connect directly to the database withouyt any API layer
I updated the Q
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
Can you please explain it like im 6 years old
And step by step? This is my first rodeo
Step 1 open VS
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
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
Yes solution stuff
dang it
If it's a C# project, it has
.csproj
for the project and .sln
for the solutionu are correct
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 muchI can get itif its recommended
Because EF Core needs 2022 I think
I heard that somewhere i think
It doesn't
ok
so i stick with 2019
ok?
Yeah, should be fine
uh
You opened the solution as a text file, in VS Code
shhhiiieeeett
I told you to open it in VS 2019
ok sorry 1 sec
Here we go here we go
You can right-click this solution now to add a new project to it
ok ill try
Library class?
ye
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)
Now I do the Nuget thingie?
? š„°
Yes, 2.0
Nuget package manager should be somewhere in the menus on the toolbar
Can't quite remember which menu it is, though
epic
You want EF Core
And you want NpgSQL if you're using Postgres
I got it
EntityFrame.Postgresql?
I did it again
ye
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?
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
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
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
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?
You can just change it in project properties, no need to recreate the whole project
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?
right-click it, open properties
It seems to be on 2.1 already, so you're good
This is the other guys packages xD
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
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
š¤ š¤
ĀÆ\_(ć)_/ĀÆ
You should probably ask on a more Unity-specific server
Alright, but whats next?
Next, you write your code
Can i start writing [Schema(my_schema), Table(my_table)] or whatever the real Attributes are?
You read through the EF Core and NpgSQL docs to learn how to set everything up
Ok ok
And, sure, you can start from your existing schema
I love it
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
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?
You can use it in the project that has the dependency
No .dlls?
No Building the Utils project?
And you can add that project as a dependency to other projects
Then, everything should build at once
Yes
You lost me
Whats my next concrete step
please
Angius
You read through the EF Core and NpgSQL docs to learn how to set everything up
Quoted by
<@85903769203642368> from #EntityFramework - Need help setting up/creating my first VS Community .NET 2.1 Project (click here)
React with ā to remove this embed.
@ZZZZZZZZZZZZZZZZZZZZZZZZZ Thanks for your help and time, I appreciate it!
Anytime
And I love pepe i love this Channel now
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.