C# Programming (Intermediate) - Lecture 10: Entity Framework Search, Multithreading Synchronization
SECourses
C# Programming (Advanced/Intermediate) Lectures (10/14) will teach you #CSharp #programming from beginner to intermediate/expert level. This course is an excellent source to learn advanced concepts in C# #coding. If you are a beginner to C#, watch our previous course lectures. The playlist link of the previous course is below.
Full playlist of the previous course: C# For Beginners ⤵️ https://www.youtube.com/playlist?list=PL_pbwdIyffskoSXySh0MdiayPJsBZ7m2o
Discord ➡️ https://bit.ly/SECoursesDiscord Patreon ➡️ https://www.patreon.com/SECourses
Technology Playlist (30+ Tutorial / Guide / News / Review Videos) ⤵️ https://www.youtube.com/playlist?list=PL_pbwdIyffsnkay6X91BWb9rrfLATUMr3
Stable Diffusion Playlist (30+ Tutorial / Guide Videos) ⤵️ https://www.youtube.com/playlist?list=PL_pbwdIyffsmclLl0O144nQRnezKlNdx3
Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.
Full playlist of this course ⤵️ https://www.youtube.com/playlist?list=PL_pbwdIyffslHaBdS3RUW26RKzSjkl8m4
You can watch for free our C# Programming, ASP .NET Core MVC programming, Machine Learning and Software Engineering related courses on our playlists page ⤵️ https://www.youtube.com/@SECourses/playlists
GitHub code repository of this course (source codes of the lectures) ⤵️ https://github.com/FurkanGozukara/Introduction-to-Programming-2-2021
In lecture 10:
- Decimal values get rounded if precision is not enough
- How to add searching / filtering feature to your entity framework context queries
- How to capture key press events application wide and do actions based on selected tab
- What is yield return and how to use yield return
- Yield return example
- What is data racing when working with multi-tasking
- How to prevent data racing with Synchronization between threads by using lock methodology
- How to achieve thread-safety when working with multiple threads/tasks
- How can we use Interlocked to ensure our operations on int32 or int64 variables are thread-safe
Decimal values get rounded if precision is not enough:
In computing, decimal values represent fractional numbers with a fixed number of digits after the decimal point. These digits are commonly referred to as the precision of the number. When performing calculations with decimal values, it is important to maintain the desired level of precision to avoid inaccuracies or rounding errors.
If the precision of the decimal value is not enough, it can lead to rounding errors, which can affect the accuracy of the final result. For example, if you have a decimal value of 3.14159265359 and you want to round it to two decimal places, the result would be 3.14. However, if the precision is not enough, the result could be rounded to 3.15 instead, resulting in an inaccurate value.
To avoid rounding errors, it is important to ensure that the precision of the decimal value is sufficient for the calculations being performed. This can be achieved by using a larger number of decimal places, or by using more precise data types such as decimal instead of float or double.
How to add searching / filtering feature to your entity framework context queries:
Entity Framework is a popular Object-Relational Mapping (ORM) framework used to access and manipulate data stored in a database. One of the common requirements of an application is to search and filter data based on specific criteria. Entity Framework provides a number of methods to achieve this functionality.
The most common method is to use the Where clause to filter data based on a specific condition. For example, to filter a list of customers based on their name, you can use the following code:
You can also use other methods such as Contains, StartsWith, and EndsWith to perform more advanced searches. For example, to search for customers whose name starts with "J", you can use the following code:
Another useful method is the OrderBy clause, which allows you to sort the data based on a specific column. For example, to sort the customers by their name in ascending order, you can use the following code:
How to capture key press events application wide and do actions based on selected tab:
Capturing key press events is a common requirement in many applications, especially those with a lot of user interaction. In order to capture key press events application wide, you can use the Application class in C#.
The Application class provides an event called KeyDown, which is raised when a key is pressed down. To capture this event, you can add a handler to the KeyDown event in the Application class. For example, to capture the "A" key press event, you can use the following code:
To do actions based on the selected tab, you can use the TabControl class in C#. The TabControl class provides an event called SelectedIndexChanged, which is raised when the selected tab is changed. ... https://www.youtube.com/watch?v=OQYZL5jH7gs
385336159 Bytes