Created
March 29, 2019 05:19
-
-
Save danielplawgo/7274afaa6485675f991a768fa9188f16 to your computer and use it in GitHub Desktop.
Cache oraz Future z EF Plus
This file contains hidden or 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
public class CacheDemo | |
{ | |
public void Run() | |
{ | |
WithCache(); | |
} | |
private void WithCache() | |
{ | |
using (var db = new DataContext()) | |
{ | |
var categories = db.Categories.Where(c => c.IsActive).FromCache().ToList(); | |
Console.WriteLine($"Categories count: {categories.Count}"); | |
categories = db.Categories.Where(c => c.IsActive).FromCache().ToList(); | |
Console.WriteLine($"Categories count: {categories.Count}"); | |
} | |
} | |
} |
This file contains hidden or 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
public class FutureDemo | |
{ | |
public void Run() | |
{ | |
WithFuture(); | |
} | |
private void WithFuture() | |
{ | |
using (var db = new DataContext()) | |
{ | |
var categoryQuery = db.Categories.Where(c => c.Id == 1).Future(); | |
var productQuery = db.Products.Where(c => c.Id == 1).Future(); | |
var category = categoryQuery.FirstOrDefault(); | |
var product = productQuery.FirstOrDefault(); | |
Console.WriteLine($"Category: {category.Name}, Product: {product.Name}"); | |
} | |
} | |
} |
This file contains hidden or 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
public class CacheDemo | |
{ | |
public void Run() | |
{ | |
WithoutCache(); | |
} | |
private void WithoutCache() | |
{ | |
using (var db = new DataContext()) | |
{ | |
var categories = db.Categories.Where(c => c.IsActive).ToList(); | |
Console.WriteLine($"Categories count: {categories.Count}"); | |
categories = db.Categories.Where(c => c.IsActive).ToList(); | |
Console.WriteLine($"Categories count: {categories.Count}"); | |
} | |
} | |
} |
This file contains hidden or 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
SELECT [Extent1].[Id] AS [Id], | |
[Extent1].[Name] AS [Name], | |
[Extent1].[IsActive] AS [IsActive] | |
FROM [dbo].[Categories] AS [Extent1] | |
WHERE [Extent1].[IsActive] = 1 |
This file contains hidden or 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
public class FutureDemo | |
{ | |
public void Run() | |
{ | |
WithoutFuture(); | |
} | |
private void WithoutFuture() | |
{ | |
using (var db = new DataContext()) | |
{ | |
var categoryQuery = db.Categories.Where(c => c.Id == 1); | |
var productQuery = db.Products.Where(c => c.Id == 1); | |
var category = categoryQuery.FirstOrDefault(); | |
var product = productQuery.FirstOrDefault(); | |
Console.WriteLine($"Category: {category.Name}, Product: {product.Name}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment