mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2025-12-19 12:05:11 +00:00
Add some failing tests
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||||
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
|
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
using EntityFrameworkCore.Projectables;
|
using System;
|
||||||
using EntityFrameworkCore.Projectables.Extensions;
|
|
||||||
using Microsoft.Data.Sqlite;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace BasicSample
|
namespace BasicSample
|
||||||
{
|
{
|
||||||
@@ -22,12 +17,14 @@ namespace BasicSample
|
|||||||
|
|
||||||
public ICollection<Order> Orders { get; set; }
|
public ICollection<Order> Orders { get; set; }
|
||||||
|
|
||||||
[Projectable]
|
[Projectable(UseMemberBody = nameof(_FullName))]
|
||||||
public string FullName
|
public string FullName { get; set; }
|
||||||
=> FirstName + " " + LastName;
|
private string _FullName => FirstName + " " + LastName;
|
||||||
|
|
||||||
[Projectable]
|
[Projectable(UseMemberBody = nameof(_TotalSpent))]
|
||||||
public double TotalSpent => Orders.Sum(x => x.PriceSum);
|
[NotMapped]
|
||||||
|
public double TotalSpent { get; set; }
|
||||||
|
private double _TotalSpent => Orders.Sum(x => x.PriceSum);
|
||||||
|
|
||||||
[Projectable]
|
[Projectable]
|
||||||
public Order MostValuableOrder
|
public Order MostValuableOrder
|
||||||
@@ -86,7 +83,7 @@ namespace BasicSample
|
|||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
using var dbConnection = new SqliteConnection("Filename=:memory:");
|
using var dbConnection = new SqliteConnection("Filename=:memory:");
|
||||||
dbConnection.Open();
|
dbConnection.Open();
|
||||||
@@ -95,6 +92,8 @@ namespace BasicSample
|
|||||||
.AddDbContext<ApplicationDbContext>((provider, options) => {
|
.AddDbContext<ApplicationDbContext>((provider, options) => {
|
||||||
options
|
options
|
||||||
.UseSqlite(dbConnection)
|
.UseSqlite(dbConnection)
|
||||||
|
.LogTo(Console.WriteLine)
|
||||||
|
.EnableSensitiveDataLogging()
|
||||||
.UseProjectables();
|
.UseProjectables();
|
||||||
})
|
})
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
@@ -130,6 +129,19 @@ namespace BasicSample
|
|||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
// What did our user spent in total
|
// What did our user spent in total
|
||||||
|
|
||||||
|
{
|
||||||
|
foreach (var u in dbContext.Users)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"User name: {u.FullName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
var result = dbContext.Users.FirstOrDefault();
|
||||||
|
Console.WriteLine($"Our first user {result.FullName} has spent {result.TotalSpent}");
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
var query = dbContext.Users
|
var query = dbContext.Users
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
|
|||||||
Reference in New Issue
Block a user