Why you need to be careful with EF Core transactions | Elliot One posted on the topic | LinkedIn (2024)

Elliot One

Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

  • Report this post

Be careful with EF Core transactions.A transaction ensures integrity and consistency in the database by performing operations as a unit of work.It can either succeed or fail as a whole.In EF Core there are two types of transactions:- Implicit Transactions- Explicit TranscationsImplicit transactions are the default behavior of EF Core. The call to SaveChanges() or SaveChangesAsync() method is regarded as a transaction.✅ Here, you must be careful to only call these methods after all the related operations have taken place.Explicit transactions, on the other hand, are defined by calling the following methods:- BeginTransaction()- Commit()/RollBack()This approach gives more granular control over the transaction boundaries, enabling more complex transactional logic.Review the slides carefully to understand both concepts and avoid a deadly mistake.♻ Reshare with your network if this is helpful.🚀 Get your daily .NET tips by following Elliot One.#systemdesign#cleancode#dotnet#csharp

269

46 Comments

Like Comment

Sarabudeen Abdul Fathah

Senior Software Developer

3d

  • Report this comment

How can we make EF transactions following case?1) OrderHeaderService2) OrderDetailService3) PaymentService

Like Reply

3Reactions 4Reactions

Alex Kovalev

Principal Software Engineer at ArdentSky, LLC

2d

  • Report this comment

nothing fatal here, basically EF runs all the operations within save changes in transaction, but sometimes we need to have it in a transaction even if we must do several save changes, for such cases, you can use explicit transaction start & commit or rollback, even more, you can use save points to control steps in a transaction

Like Reply

2Reactions 3Reactions

Jamal Arghavani

Software Engineer @ Mofid Securities | .Net Developer

3d

  • Report this comment

Good point, thanks for sharing Elliot One

Like Reply

3Reactions 4Reactions

Adnan Maqbool Khan

Team Leader | .NET | Microservices | Azure | Vue | React | Angular | Typescript | RabbitMQ | SQL | MSTest | Cypress

3d

  • Report this comment

Very informative.

Like Reply

3Reactions 4Reactions

Great share... I have short discussion about transaction with my engineers.... I believe they're should be centralised, decorator pattern. What do you think?

Like Reply

3Reactions 4Reactions

Amir Eslamzadeh

.Net BackEnd Programmer | API | Microservicess

3d

  • Report this comment

Thanks, it's very important point

Like Reply

2Reactions 3Reactions

Romain Ottonelli Dabadie

👪 Proud husband & dad | 💻 Software Engineer | .NET Enthusiast

3d

  • Report this comment

Good point! Elliot One

Like Reply

1Reaction 2Reactions

Ghulam Murtaza

Full Stack Engineer at e-strats || .Net Core || Asp.Net MVC || JavaScript || SQL Server || React js

2d

  • Report this comment

Thanks for sharing

Like Reply

1Reaction 2Reactions

Poorna Soysa

Tech Enthusiast | .Net | C# | Azure | AWS

3d

  • Report this comment

Interesting topic Elliot. Thanks for sharing.

Like Reply

2Reactions 3Reactions

SERKUT YILDIRIM

Microsoft MVP | Helpful Posts About .NET, C# and Visual Studio

3d

  • Report this comment

Nice explanation, thanks for sharing Elliot

Like Reply

2Reactions 3Reactions

See more comments

To view or add a comment, sign in

More Relevant Posts

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    Software Engineering is Beyond Just Web ApplicationsLet's not forget that software engineering is a vast field.It encompasses various sub-fields such as:- Embedded Systems- Game Development- Systems Software- Artificial Intelligence & Machine Learning- Aerospace and Defense- Healthcare Technology- Mobile ApplicationsSpecialization in each sub-field can take a long time. However, you can still get the feeling of working in a few of them. You can try building at least a few applications from different areas. Solely focusing on CRUD applications won't take you far. That's what tutorial videos teach you: CRUD applications.It doesn't matter what the idea of the application is—simply performing CRUD operations in a web application is not a sustainable approach to learning deeper concepts.#softwareengineering #softwaredevelopment

    59

    10 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    Middleware enhances the functionalities of your application.They inject additional behavior into the request pipeline.You can utilize them to:- Handle Exceptions- Serve Static Files- Integrate Authentication- Enable Logging- Define RoutesCustom middleware particularly helps to include customized behavior.In ASP .NET Core, the IMiddleware interface provides the facility to define custom middleware.This interface helps create strongly typed middleware that improves code reusability and organization.The InvokeAsync() is the only method that needs to be implemented.You should also pass the control to the next middleware, if not, your request will be short-circuited.Eventually, you need to register the middleware to the middleware pipeline.It can be either added using "UseMiddlware<>()" or using an extension method for a cleaner implementation.✅ In summary, implement custom middleware by implementing IMiddleware and use an extension method to include it cleanly in the middleware pipeline.📌 Let's review the slides for better understanding.♻ Reshare with your network if this is helpful.🚀 Get your daily .NET tips by following Elliot One.#dotnet#cleancode

    104

    18 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    Just a quick reminder: You don't need to know everything.Too many times we get confused about what we should learn or do next.- We need more simplification rather than complexity.There are many languages, frameworks, domains, ... out there.It's impossible to catch up with all of them.We should focus on a particular area over a specific period while we also have some general understanding of other things.We shouldn't hamper our growth by following a bit of everything. That's not a sustainable strategy for long-term success in this field.#softwareengineering

    68

    17 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    Discard is a powerful feature that helps you ignore values.In C#, you can use the Discard operator "_" to ignore an expression result.You can ignore the values of:- A task result- Pattern Matching Targets- Tuple Members- "Out" Parameters- An Expression ResultIgnoring task results and out parameters are helpful, however, they are lesser-known usages.All you need to do is to declare the variable as underscore "_".This will ignore the values mentioned earlier.✅ When a value is ignored, it signifies that it's not required in further operations and calculations, to the compiler and developers.Review the slides for different usages of Discards.Have you used Discards before?♻ Reshare with your network if this is helpful.🚀 Get your daily .NET tips by following Elliot One.#dotnet#cleancode#softwareengineering

    184

    17 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    Collection Literals syntax is one of the latest improvements in modern C#.It helps simplify the initialization and combining of different collection types.It supports Arrays, Spans, Lists, and any collection type that already utilizes the collection initializer syntax.The Spread operator, meanwhile, helps inline different collections.Put ".." before the collection's name to use the spread operator.Combining collection literals with spread operator simplifies working with collections types and improves code readability. Be careful: Collection Litearls don't support the "var" keyword.What is your experience using these features?♻ Reshare with your network if this is helpful.🚀 Get your daily .NET tips by following Elliot One.#dotnet#csharp#systemdesign#cleancode

    138

    20 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    If you haven't familiarized yourself with Pattern Matching, here is the last opportunity!I just compiled a comprehensive set of slides about Pattern Matching in C#.This is a game-changer feature in modern c#.It helps reduce verbosity in code and get rid of unwanted if-else statements.Pattern Matching is useful for determining an expression against some criteria, checking against null values, and finding matches in switch expressions.Slides cover the following patterns:- Declaration and Type Patterns- Constant Pattern- Relational Patterns- Logical Patterns- Property Pattern- Positional Pattern- Tuple Pattern- var Pattern- Discard Pattern- Parenthesized Pattern- List PatternIt can be daunting at first, however, reviewing all examples in one PDF can help you understand their differences and learn them faster.Take a look at the slides and let me know your thoughts.♻ Reshare with your network if this is helpful.🚀 Get your daily software engineering tips from Elliot One.#csharp#dotnet#cleancode#softwareengineering

    148

    19 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    🔍 Seeking London-Based Software Engineering Role! 🔍Dear LinkedIn community,I'm looking for a software engineering/full-stack role in London.Currently, I'm studying MSc. in Software Engineering with Cloud Computing at City, University of London, with an expected graduation date of October 2024.I'm proficient in C#, ASP.NET Core, .NET, Javascript, and more. If your company is seeking a dedicated and adaptable professional, let's chat!Feel free to reach out via LinkedIn or email me at elliotoneofficial@gmail.com.Looking forward to connecting with you soon!#londonjobs#london#dotnet#csharp#aspcore#aspnetcore#softwareengineering

    63

    28 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    SOLID Principles are still a cornerstone of building robust software.I created a comprehensive set of slides for them, using C# language.SOLID stands for 5 principles:1. Single Responsibility Principle (SRP)2. Open/Closed Principle (OCP)3. Liskov Substitution Principle (LSP)4. Interface Segregation Principle (ISP)5. Dependency Inversion Principle (DIP)These principles provide a guideline for building more maintainable code.Here is what each of them means:1. SRP: A class/method should have only one reason to change.2. OCP: Software entities should be open for extension but closed for modification.3. LSP: Subtypes must be substitutable for their base types without altering correct behavior.4. ISP: Clients should not be forced to depend on interfaces they don't use.5. DIP: Depend on abstractions, not on concretions. Just know you don't have to follow them religiously the whole time.The key to understanding them is to apply them while considering the trade-offs involved in each decision.Review the slides, noting any violations.♻ Reshare with your network if this is helpful.🚀 Get your daily software engineering tips from Elliot One.#cleancode#softwareengineering#systemdesign#dotnet#csharp

    1,449

    81 Comments

    Like Comment

    To view or add a comment, sign in

  • Elliot One

    Full Stack Software Engineer | Elevating .NET Engineers | Experienced in Software Engineering, System Design, Cloud, and AI/ML Applications | Solopreneur & Founder

    • Report this post

    Sessions maintain user state across multiple requests.They can be utilized for various purposes, such as:- Implementing shopping carts- Keeping authentication status- Providing a customized user experience- Tracking user activity- Keeping temporary dataConfiguring sessions in ASP .NET Core is straightforward.All needed is to add the service and middleware for sessions.Then, the session values can be set and updated.However, you need to be aware of best practices:- Sessions might impose security risks so the data should be encrypted.- Avoid storing large amounts of data in sessions to avoid performance bottlenecks.- Configure timeouts to mitigate security risks by invalidating session data.- Consider using distributed cache providers such as Redis for distributed systems.In the slides, I used sessions to implement a simple anonymous shopping cart. Please review the code in the slides and let me know your thoughts.♻ Reshare with your network if this is helpful.🚀 Get your daily .NET tips by following Elliot One.#csharp#dotnet#systemdesign

    190

    14 Comments

    Like Comment

    To view or add a comment, sign in

Why you need to be careful with EF Core transactions | Elliot One posted on the topic | LinkedIn (51)

Why you need to be careful with EF Core transactions | Elliot One posted on the topic | LinkedIn (52)

19,652 followers

  • 240 Posts

View Profile

Follow

Explore topics

  • Sales
  • Marketing
  • Business Administration
  • HR Management
  • Content Management
  • Engineering
  • Soft Skills
  • See All
Why you need to be careful with EF Core transactions | Elliot One posted on the topic | LinkedIn (2024)
Top Articles
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 5736

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.