-
-
Save mortezadalil/72f1a53141d22e09e3e674ce8e7e165b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defining a Shadow Property | |
public class ApplicationDbContext : DbContext | |
{ | |
public DbSet<Book> Books { get; set; } | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.Entity<Book>().Property<DateTime>("ModifiedDate"); | |
} | |
} | |
public class Book | |
{ | |
public int Id { get; set; } | |
public string Title { get; set; } | |
} | |
//Using Shadow Properties in a Query | |
using (var context = new ApplicationDbContext()) | |
{ | |
var books = context.Books | |
.OrderByDescending(b => EF.Property<DateTime>(b, "ModifiedDate")) | |
.ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment