Faker
Explore posts from servers? operator and property assigned to =null! meaning in EF core database context
Hello guys, this is a book class that I scaffolded using EF Core. I have a few questions. What does that mean when we use
= null!
and what does that mean when we say a type of associated with ?
. What does it convey in terms of database context, like nullable/ not nullable?
I know that ?
is used to say that we allow a data type to have null value. But what does it mean here?
Also, =null
basically means we are assigning null as soon as we are creating, but what does the !
mean then?
Whys is the =null!
important please, can we omit it?44 replies
Is it possible to change Migrations folder path when updating database using UI tools for EF Core
Hello guys, when using the UI tools for migration in rider, normally, we look into the Migrations folder where our project is. For instance, if our .csproj is in Learning, we would look for Migrations sub-folder in Learning. My question is, can we change that to look inside Library/Migrations instead?
The idea is, I wanted several folders to hold different dbContext Migrations. Like say one for School, one for Library etc.
I was able to specify where my migrations go when I add to it, like Library/Migrations. BUT when I update database, it seems it still look into Migration folder in Learning and so it doesn't recognise/find any migration related to the one I want to process.
28 replies
✅ Purpose of generating SQL Script in EF Core
Hello guys, was just wondering, what is the purpose of generating the SQL script in EF Core? Normally, we need to update the migration then we would be able to generate a sql script. So what's the point of generating the script? Is it because normally, all test/migrations will first be done in a testing/development environment and so generating the script will show us whether our sql script matches the scheme we wanted to have or it's useful because a database administrator can give his feedbacks/opinions before proceeding to production environment?
8 replies
✅ Should we include database name in connection string when creating new db using EF core ?
Hello guys, I have an existing connection string with an existing database name "Library". I wanted to create a new database Students. I used the existing connection string and in that, their was the key Database with value Library. What happens is that I didn't get a database of Students being generated but rather, I get Students table inside Library with the migration file in the Library database. Is this normal? Should I omit the key database in the connection string? Or I just change database name in connection string to Students?
25 replies
✅ Why the need to create a database using EF core and not do it manually using SQL
Hello guys, I'm currently learning the EF core so that I can connect with my database using SQL Server. I have a question. I noticed that if we want to create a database using EF core, we need to create a dbContext, a specific instance, like a Student class with its properties etc. My question is, is all that required? Can't we not just use SQL statement to create all that using SQL Server? Isn't it easier? Or there is use cases of when we absolutely need to use C# code?
68 replies
✅ Database window in rider/visual studio
Hello guys, I was watching some videos, I noticed that the developers make use of an in-built database window. Like say I'm saving my data to SSMS, each time I need to write a query, I would change application and go to SSMS and write a query statement, observe the result set and go back to my IDE. So, there is kind of a "short-cut" like where our IDE acts as a UI just like the SSMS?
20 replies
✅ using keyword for resource management in C#
Hello guys, I just learnt about the
using
keyword for resource management in C#. What I understood about it is that whenever we are done with using specific resources, like dealing with database operations, the using
keyword automatically dispose/free memory (please add up to the use of this keyword if I'm missing anything or incorrectly saying things). I have one question though. I read that even though if our console application crashes, IF
we are not using the using
keyword or try-catch-finally block, the resource allocated isn't freed immediately, like it's still allocated to SQL Server for example. I'm a bit lost here, our app is no longer "alive", then how come resources is still available to our SQL server database.
Also, when using the using
keyword, we don't need to close the database connection like connection.close()
anymore? This is already been taken care of under the hood?49 replies
✅ App.config file and .env file
Hello guys, this doesn't concern only C# but I think it's in general. What is the difference between a .config file and .env file? Both stores sensitive data no? For example, our database connection string can be stored in either one. Which one should I choose and why.
Second thing... when we create a solution in C#, does it automatically create an App.config why? if no, how to proceed to create one please.
31 replies
✅ is there a difference between NET core and .NET and .NET framework ?
Hello guys, I was reading a bit, I noticed that .NET core, .NET and .NET framework doesn't refer to the same thing, like I read for eg that .NET framework is mainly for windows legacy system. Can someone elaborate on there differences please; is it important to know how they differ?
6 replies
✅ ADO.Net Vs Entity Framework Core for database connectivity
Hello guys, can someone explain what is the difference between these 2 frameworks please (ADO.Net Vs Entity Framework core). From what I've read, the ADO one is for "low-level" stuff; what do we mean by that? I know that we write raw SQL queries using ADO. Why don't we use EF core? I know EF core contains in-built function that allows us to mimic SQL queries. What can't we do in EF core that can be done in ADO.net? And which framework should I use please.
Last thing, I read that EF core is an ORM but ADO.Net isn't, is that correct? This is why we need to write raw SQL queries ?
21 replies
✅ Resource to learn how to connect SQL Server to C#
Hello guys, I need to connect C# to SQL Server Management Studio. I was introduced to ADO.Net and the Entity Framework core. But I don't really understand them yet. Is there any recommended resource to learn both of them and goes beyond that, by learning properly how to get started with connected SQL Server Management Studio with C# please (any docs?).
15 replies
✅ How call stacks work in recursive calls
Hello guys, I've implemented a small funtion to find any nth term in the fibonnaci sequence.
I don't understand how the recursive calls work under the hood though. Like, I know that num-1 is called first, then when all its call stack is kind of "over" we move to the right hand side but this is still vague. I was wondering if there was kind of a visualization tool to see what's hapenning and what's being return for each call.
7 replies
✅ Can we find min and max values of any given array directly? (use of any built-in methods?)
Hi guys, I wanted to find min and max value of an array of numbers. I can do it using a loop, comparing each index. I have to manually set up everything and the algorithm is not as much efficient I think. So I was wondering if there was any in-built method or any better algorithm in terms of efficiency please
24 replies
✅ StringBuilder in C#
Hello guys, I was just reading a bit about string manipulation, then I came across the class "StringBuilder". I just read a bit about it. From what I've understood, it makes as if our string become "mutable" in the sense that we can directly modify our original string? (or it just shares the same memory location with another string?).
My question is, is StringBuilder Class still used? I mean like we have powerful methods for string now, like split, join, remove, substring etc. If so, can someone give any use case where we need to use StringBuilder please. (ALSO, please confirm whether I've said above about how StringBuilder works is true please)
33 replies
✅ out vs ref keyword usage
Hello guys, can someone explain when to use the out keyword and when to use the ref keyword please. I understand that in both scenarios, behind the scene, a pointer is passed so that any change made is reflected back. I also read that ref need to be initialized before passing value as argument while out doesn't but out need to be assigned a value inside the method itself.
I don't understand where one is used over the other though... can someone explain please, any use cases/best practices.
47 replies
Data structure in C# - Dictionary<TKey, TValue>
Hello guys, I have a quick question... I have a miss-conception, when we say the term "dictionary" ; is it just another term for a hash map/hash table? Or it just uses the idea of hash table behind the scenes? Because if I remember correctly, we also have the concept of Hash set where there (I think), it takes only one generic parameter. How does these 2 differs in terms of one is key-value and the other is just the value please, I'm a bit confused.
56 replies
How to read stack trace errors
Hello guys, consider the following error:
Can someone explain how should I proceed to "decrypt" the stack trace error please. Should I read from top to bottom or bottom to top? How to interpret each line and which lines are the most important ones where it actually tells us the parent line which causes the error please
40 replies
Purpose and use of nested classes in C#
Hello guys, sorry to disturb you all; can someone explain the idea of using nested classes in C# please. For example, consider the following code:
I want to implement a linkedList by scratch in C#. Why not just use a class of "Node" or "LinkedList" ? why we should have both, what if we don't have them?
69 replies
What is an Enumerator, Iterator, IEnumerable and IEnumerator and relation with yield return keyword
Hello guys, from what I've read, an enumerator is what get returns from an IEnumerable, which is itself a sequence of element that can be iterated over.
So basically, an enumerable gives us a series of element. Then on these series of element, one by one, we can get an "enumerator" which will allow us to access each one of them one at a time. The enumerator uses methods to manually control the looping process. However, an enumerator can also return an iterator which does the exact same job behind the scenes, it's just syntax sugar; using the command
yield return
, we return an iterator which behind the scenes will just methods like .MoveNext() from an enumerator.
It's still a bit unclear in my head, I believed I mixed things up, would really appreciate if someone can add to what I've said and correct me where I went wrong please.
Also, one thing, consider the following code:
the IEnumerable is an interface, right? We can use interface as data types? why use interface as data types?28 replies