Course info

Level

Intermediate

Updated

Dec 7, 2016

Duration

1h 55m

Description

Marten can be used as a replacement or alternative to other document databases such as MongoDb or RavenDb and can also be an alternative to ORMs such as Entity Framework. While Marten is easy to get started with, it also provides an array of customization, diagnostic, data manipulation, and performance related features that can be additionally employed. In this course, Working with Data and Schemas in Marten, you'll learn how to improve query performance, diagnose and log SQL statements, implement offline optimistic concurrency, and customize PostgreSQL schema objects. First, you'll discover how to log and diagnose SQL queries and DDL commands generated by Marten. Next, you'll learn how to prevent data loss with offline optimistic concurrency and how to soft-delete documents. Then, you'll move on to learning how to reduce database round trips, improve PostgreSQL query performance, and how to reduce client CPU costs. Finally, you'll discover how to take control over the PostgreSQL schema objects that Marten defines and creates. By the end of this course, you'll have a better understanding of how to work with data and schemas in Marten.

Section Introduction Transcripts

Course OverviewHi everyone. My name is Jason Roberts. Welcome to my course Working with Data and Schemas in Marten. I'm a Microsoft. NET MVP, freelance developer, and author. In this course, we're going to learn how Marten allows us to customize, diagnose, and improve data access performance. Some of the major topics that we'll cover in this course include how we can see what SQL statements are being issued to the database, additional techniques we can take advantage of when we're modifying data, such as offline concurrency, how we can improve query performance, and also how we can take control of the underlying PostgreSQL schema. By the end of this course, you'll understand how to work with data, queries, and schema in more depth and how to use diagnostics to investigate when things aren't working as expected. Before beginning the course, you should be familiar writing basic C# code in Visual Studio and also with the fundamentals of using the Marten library. I hope you'll join me on this journey with the Working with Data and Schemas in Marten course at Pluralsight.

Modifying Document DataHi, welcome back. In the previous module we learned how we can diagnose and log the SQL or DDL commands being sent to Postgres from Marten. In this module we're going to be learning some additional techniques we can use when we want to modify data in the underlying Postgres database. In this module we're going to start off by learning about the offline optimistic concurrency pattern. So we'll learn how we can configure this in Marten, and we'll learn how it can help us to prevent data loss, or the overwriting of data when we have multiple concurrent sessions accessing and modifying data at the same time. We'll learn that we can configure Marten to soft-delete documents in the underlying Postgres database. This means that when we tell Marten to delete a document, it doesn't actually physically get removed from the database, and by default, it doesn't get returned in our LINQ queries. One application for soft deleting is to maintain data for audit purposes without having to add additional application logic to deal with this. In this module we'll also learn that if we have a large number of documents that we want to insert into the underlying Postgres database, how we can use Marten's bulk document insertion features to do this in a more convenient and performant way. Finally we'll learn about some advanced features of Marten that allow us to delete documents in the underlying document store, and even delete schema items related to document types. This can be useful if you're writing integration tests and you want to ensure that the integration test database is set up in a known state before the integration tests execute. So let's kick off this module by learning more about the offline optimistic concurrency model.