FormattableString
string nameParameterValue = "Title2";
FormattableString formattableStringV2 = $"""
UPDATE dbo.Books
SET ModifiedDate = GETUTCDATE(),
Name = {nameParameterValue}
WHERE Name = 'Title1'
""";
//EF7
rows = dbContext.Database.ExecuteSql(formattableStringV2);
or
FormattableString queryEmployee = $"""
SELECT Id, FirstName + ' ' + LastName as FullName, FirstName FROM dbo.Employee
""";
var models = dbContext.Database.SqlQuery<ActorViewModel>(queryEmployee).ToList();
Concurrency
Concurrency conflicts occur when one user retrieves an entity's data to modify it, and then another user updates the same entity's data before the first user's changes are written to the database. How you handle those conflicts depends on the nature of the changes being made.
[Timestamp]
public byte[] Version { get; set; }
builder.Property(i => i. Version). IsRowVersion().IsConcurrencyToken(false);
builder.Property(i => i. Version). IsRowVersion();
Using Transactions
If the transaction is committed, all of the operations are successfully applied to the database. If the transaction is rolled back, none of the operations are applied to the database.
Global Query Filters
During model creating, adding option
modelBuilder.Entity<Post>().HasQueryFilter(p => !p.IsDeleted);
If needs to disable
blogs = await db.Blogs
.Include(b => b.Posts)
.IgnoreQueryFilters()
.ToListAsync();