From f2120188b880096f9cc2c355212fafc025f6ff86 Mon Sep 17 00:00:00 2001 From: pasquizzat Date: Wed, 22 Feb 2023 12:06:25 +0100 Subject: [PATCH] ef : on avance dans les requetes linq --- Sources/BddTests/Program.cs | 5 ++- Sources/BddTests/laBdd.db | Bin 20480 -> 20480 bytes Sources/LeagueOfLegends.sln | 2 +- Sources/Model2/ChampionContext.cs | 5 +-- Sources/TrucAuMilieu/DataBdd.Champions.cs | 36 +++++++++++++++------- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs index a0cc9ae..fd35a44 100644 --- a/Sources/BddTests/Program.cs +++ b/Sources/BddTests/Program.cs @@ -9,10 +9,9 @@ Console.WriteLine("allo?"); var dataMgr = new DataBdd(); -await dataMgr.ChampionsMgr.AddItem(c2); -Console.WriteLine("champion ajouté"); +//dataMgr.ChampionsMgr.AddItem(c2); -List list = dataMgr.ChampionsMgr.GetItems(0, 5).Result.ToList(); +List list = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList(); /* diff --git a/Sources/BddTests/laBdd.db b/Sources/BddTests/laBdd.db index fd2359e406aa5dd5643f4b97fce5da13337527a1..fc25159ba4a1cff77238020412f13517d20b0638 100644 GIT binary patch delta 79 zcmZozz}T>Wae_1>??f4AM&6AHOZ26<`C1tGZ}4y6@8D11x8N7xd%<^rZw6l{8SDu7;EzkyL3TDZU9hu6RiLM delta 54 zcmV-60LlM=paFoO0gxL33y~Z{0SmEUq%Rf;4wwKB*blG|h!0>7I1dmG=nlXRn6nWO Meh#ykK4%dD39(2Ih5!Hn diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index d81a4f4..af69a48 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -30,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrucAuMilieu", "TrucAuMilie {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} = {D7FE55BA-1CEE-4C9D-B2FA-674D61F1B7A5} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiDePaul", "ApiDePaul\ApiDePaul.csproj", "{245F7BAC-8487-4510-8066-D12B5B2B816B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDePaul", "ApiDePaul\ApiDePaul.csproj", "{245F7BAC-8487-4510-8066-D12B5B2B816B}" ProjectSection(ProjectDependencies) = postProject {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} EndProjectSection diff --git a/Sources/Model2/ChampionContext.cs b/Sources/Model2/ChampionContext.cs index 14a1003..f683cd2 100644 --- a/Sources/Model2/ChampionContext.cs +++ b/Sources/Model2/ChampionContext.cs @@ -12,10 +12,11 @@ namespace LibEntityFramework protected override void OnConfiguring(DbContextOptionsBuilder options) { - if (!options.IsConfigured) + /*if (!options.IsConfigured) { options.UseSqlite("DataSource=laBdd.db"); - } + } */ + options.UseSqlite("DataSource=laBdd.db"); } } } diff --git a/Sources/TrucAuMilieu/DataBdd.Champions.cs b/Sources/TrucAuMilieu/DataBdd.Champions.cs index dfdbefc..394f6aa 100644 --- a/Sources/TrucAuMilieu/DataBdd.Champions.cs +++ b/Sources/TrucAuMilieu/DataBdd.Champions.cs @@ -2,6 +2,7 @@ using Model; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -13,14 +14,16 @@ namespace TrucAuMilieu public ChampionContext contextCh = new ChampionContext(); public class ChampionsManager : IChampionsManager { + private readonly DataBdd parent; public ChampionsManager(DataBdd parent) => this.parent = parent; public async Task AddItem (Champion? item) - {// ya comme une erreur le truc n'est pas save dans la bdd :( - await parent.contextCh.AddAsync(item.ChampToEf); + { + await parent.contextCh.AddAsync(item.ChampToEf()); await parent.contextCh.SaveChangesAsync(); - return item; //ou elle est lerreur je vais menerve elle est ou lerreur >:( + Debug.WriteLine("champion ajouté"); + return item; } public Task DeleteItem(Champion? item) @@ -28,17 +31,31 @@ namespace TrucAuMilieu throw new NotImplementedException(); } - public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)/* + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + if (descending) + { + return await Task.FromResult(parent.contextCh.Champs.OrderByDescending(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + } + else + { + var hi = parent.contextCh.Champs.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp()); + return Task.FromResult(hi); //ya une petite betise ça marche pas trop menfin bref c'est a corriger + } + + } + /* + => parent.contextCh.Champs.Take(count).Skip(index). /* => parent.contextCh..GetItemsWithFilterAndOrdering( c => true, index, count, - orderingPropertyName, descending);*/ - {// hihihi les arguments servent à rien pour l'instant y'a zero arguments utilises oupsi :3 + orderingPropertyName, descending); + {// hihihi les arguments servent à rien pour l'instant y'a zero arguments utilises oupsi List lch = parent.contextCh.Champs.Take(count).Skip(index).ToList(); List items = new List(); foreach (var c in lch) { items.Add(c.EfToChamp()); } return items; - } + }*/ public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) { @@ -70,10 +87,7 @@ namespace TrucAuMilieu throw new NotImplementedException(); } - public Task GetNbItems() - { - throw new NotImplementedException(); - } + public Task GetNbItems() => Task.FromResult(parent.contextCh.Champs.Count()); public Task GetNbItemsByCharacteristic(string charName) {