tama
How does EF know what database to use?
Hello there.
I am building an entity related management system, and I'm wondering how EF know what database I want it to use. I am using .Net 8, and the only place I have referenced the database was in the Program.cs file, however, I have commented out that part and it is still able to update my database. How is that possible?
19 replies
✅ Required property
Hello there.
I am creating a class with some required properties. I have decorated them with the [Required] thing, however, it's still complaining. Are you supposed to have both [Required] and the required keyword? Example:
Should it be this instead?:
11 replies
Project requirements?
Hello there.
I am about to publish a project I have written, however, I am little unsure how you usually handle libraries when publishing the project. In Python, you usually have a requirements.txt file listing all the libraries used by the project. How do you do that in C#? I want to ensure the recipient is able to run the project without having to look at the code.
4 replies
Best practice for class constructors?
Hello there.
I'm creating a class with one private and one public variable. I am a little unsure how the constructor should work when this is the case. As an example:
Does it make sense to declare them first, and then assign them in the initializor? Also, are you supposed to add
{ get; set; }
to the class variable when it's also part of the constructor?
I am also unsure what the best practice is for variable names in C#. Some places I have seen names with capital first letter, other times I see something like exampleVariable
. I come from Python, where we use _variable_name
for private variables, do you also use the underscore in C#?8 replies
Entity DB object with immutable variables
Hello there.
I am kind of new to C# and I am doing a project about some database management system. I have created an object for the database and my first migration went well. Now, part of the challenge with this project is that some class variables for the database object needs to be readonly after being set in the initializer. I am a little unsure if this is something you can achieve with some keywords or if I need to create my own logic for ensuring the fields are never changed. As an example:
I have a class Car with three variables: Manufacturer, Model and Owner. Now, Manufacturer and Owner will always stay the same for the object in the database but Owner can of course change. To achieve this, I have so far written:
Is this sufficient?
18 replies