-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
423 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace Vogen.EfCoreTest; | ||
|
||
public static class EfCoreScenario | ||
{ | ||
public static void Run() | ||
{ | ||
using var context = new MyContext(); | ||
//context.Database.Migrate(); | ||
|
||
AddAndSaveItems(amount: 10); | ||
AddAndSaveItems(amount: 10); | ||
|
||
PrintItems(); | ||
|
||
FilterItems(); | ||
|
||
return; | ||
|
||
static void AddAndSaveItems(int amount) | ||
{ | ||
using var context = new MyContext(); | ||
|
||
for (int i = 0; i < amount; i++) | ||
{ | ||
var entity = new EmployeeEntity | ||
{ | ||
Name = Name.From("Fred #" + i), | ||
Age = Age.From(42 + i), | ||
Department = Department.From("Quarry"), | ||
HireDate = HireDate.From(new DateOnly(1066, 12, 13)) | ||
}; | ||
|
||
context.Entities.Add(entity); | ||
} | ||
|
||
context.SaveChanges(); | ||
} | ||
|
||
static void PrintItems() | ||
{ | ||
using var ctx = new MyContext(); | ||
|
||
var entities = ctx.Entities.ToList(); | ||
Console.WriteLine(string.Join(Environment.NewLine, entities.Select(e => $"ID: {e.Id.Value}, Name: {e.Name}, Age: {e.Age}"))); | ||
} | ||
|
||
static void FilterItems() | ||
{ | ||
Console.WriteLine(); | ||
Console.WriteLine("FILTERING ITEMS..."); | ||
using var ctx = new MyContext(); | ||
|
||
int age = 50; | ||
// var entities = from e in ctx.Entities where e != null && e.Age == age select e; | ||
// var entities2 = ctx.Entities.Where(e => e != null && e.Age == age); | ||
|
||
DbSet<EmployeeEntity> step1 = ctx.Entities; | ||
//IQueryable<EmployeeEntity> step2 = step1.Take(4); | ||
var step3 = step1.Where(e => e.Age == age); | ||
|
||
|
||
|
||
// Console.WriteLine(string.Join(Environment.NewLine, entities.Select(e => $"ID: {e.Id.Value}, Name: {e.Name}, Age: {e.Age}"))); | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.