Przeglądaj źródła

update packages for qdr.qdr.fnd.core.data

Dalibor Votruba 2 lat temu
rodzic
commit
dcb2450c47

+ 1 - 1
qdr.fnd.core.data.itfc/Domain/IDomain.cs

@@ -2,7 +2,7 @@
 {
     public interface IDomain
     {
-        TEntitySet GetDbSet<TEntitySet>();
+        TEntitySet? GetDbSet<TEntitySet>();
         IUnitOfWork<TDomainContext> CreateUnitOfWork<TDomainContext>() where TDomainContext : IDomain;
         void Commit();
     }

+ 1 - 1
qdr.fnd.core.data.itfc/Repository/IDaoRepository.cs

@@ -8,7 +8,7 @@ namespace Quadarax.Foundation.Core.Data.Interface.Repository
     public interface IDaoRepository<TKey, TDao> : IRepository where TDao : IDao<TKey> where TKey : IEquatable<TKey>
     {
         public IQueryable<TDao> Query(IPaging paging, bool usingUncomited = false);
-        public TDao Get(TKey id);
+        public TDao? Get(TKey id);
         public IQueryable<TDao> Get(IEnumerable<TKey> ids);
         public TDao Set(TDao entity);
         public IEnumerable<TDao> Set(IEnumerable<TDao> entities);

+ 7 - 7
qdr.fnd.core.data/Domain/DataDomain.cs

@@ -8,22 +8,22 @@ namespace Quadarax.Foundation.Core.Data.Domain
 {
     public abstract class DataDomain : DbContext, IDomain
     {
-        private MethodInfo _mtSet;
-        private MethodInfo _mtgSet;
+        private MethodInfo? _mtSet;
+        private MethodInfo? _mtgSet;
         protected DataDomain(DbContextOptions options) : base(options)
         {
 
         }
-        public TEntitySet GetDbSet<TEntitySet>()
+        public TEntitySet? GetDbSet<TEntitySet>()
         {
-            //TODO: comment because db constext is in this scope static
+            //TODO: comment because db context is in this scope static
             //if (_mtSet == null)
                 _mtSet = GetType().GetMethod(nameof(DbContext.Set), Type.EmptyTypes);//GetType().GetMethod("Set");
             //if (_mtgSet==null)
-                _mtgSet = _mtSet.MakeGenericMethod(typeof(TEntitySet).GetGenericArguments().First());
+                _mtgSet = _mtSet?.MakeGenericMethod(typeof(TEntitySet).GetGenericArguments().First());
 
-            var returnValue = _mtgSet.Invoke(this, new object[] {});
-            return (TEntitySet)returnValue;
+            var returnValue = _mtgSet?.Invoke(this, new object[] {});
+            return (TEntitySet?)returnValue;
         }
 
         public IUnitOfWork<TDomainContext> CreateUnitOfWork<TDomainContext>() where TDomainContext : IDomain

+ 2 - 2
qdr.fnd.core.data/Domain/UnitOfWork.cs

@@ -15,12 +15,12 @@ namespace Quadarax.Foundation.Core.Data.Domain
 
         public void Commit()
         {
-            Context.Commit();
+            Context?.Commit();
         }
 
         protected override void OnDisposing()
         {
-            Context = default;
+            Context = default!;
         }
     }
 }

+ 2 - 1
qdr.fnd.core.data/Entity/Entity.cs

@@ -6,9 +6,10 @@ namespace Quadarax.Foundation.Core.Data.Entity
 {
     public abstract class Entity<TKey> : IDao<TKey> where TKey : IEquatable<TKey>
     {
+       
         #region *** Properties ***
 
-        public virtual TKey Id { get; set; }
+        public virtual TKey Id { get; set; } = default!;
 
         #endregion
 

+ 5 - 10
qdr.fnd.core.data/Entity/NoKey.cs

@@ -4,21 +4,16 @@ namespace Quadarax.Foundation.Core.Data.Entity
 {
     public class NoKey : IEquatable<NoKey>
     {
-        public Guid Hash { get; }
+        public Guid Hash { get; } = Guid.NewGuid();
 
-        public NoKey()
+        public bool Equals(NoKey? other)
         {
-            Hash = Guid.NewGuid();
-        }
-
-        public bool Equals(NoKey other)
-        {
-            if (other == null)
+            if (other == null!)
                 return false;
             return Hash == other.Hash;
         }
 
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (ReferenceEquals(null, obj)) return false;
             if (ReferenceEquals(this, obj)) return true;
@@ -31,7 +26,7 @@ namespace Quadarax.Foundation.Core.Data.Entity
             return Hash.GetHashCode();
         }
 
-        public static bool operator ==(NoKey left, NoKey right)
+        public static bool operator ==(NoKey? left, NoKey right)
         {
             return Equals(left, right);
         }

+ 7 - 14
qdr.fnd.core.data/Mapper/MapperGuidExt.cs

@@ -7,54 +7,48 @@ namespace Quadarax.Foundation.Core.Data.Mapper
 {
     public static class MapperGuidExt
     {
-        public static TDto Map<TDao, TDto>(this TDao dao)
+        public static TDto? Map<TDao, TDto>(this TDao dao)
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
-            if (dao == null) return null;
             return Mapper<MapperGuid>.Instance.Map<TDao, TDto>(dao);
         }
 
-        public static TDao MapDto<TDto, TDao>(this TDto dto)
+        public static TDao? MapDto<TDto, TDao>(this TDto dto)
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
-            if (dto == null) return null;
             return Mapper<MapperGuid>.Instance.Map<TDto, TDao>(dto);
         }
 
-        public static void CopyToDto<TDto, TDao>(this TDto @from, TDao to)
+        public static void CopyToDto<TDto, TDao>(this TDto @from, TDao? to)
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
-            if (@from == null) return;
             if (to == null) return;
             Mapper<MapperGuid>.Instance.Update(@from,to);
         }
 
-        public static void CopyToDto<TDto, TDao>(this TDao @from, TDto to)
+        public static void CopyToDto<TDto, TDao>(this TDao @from, TDto? to)
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
             if (to == null) return;
-            if (@from == null) return;
             Mapper<MapperGuid>.Instance.Update(@from,to);
         }
 
 
-        public static List<TDto> MapList<TDao, TDto>(this IQueryable<TDao> dao)
+        public static List<TDto>? MapList<TDao, TDto>(this IQueryable<TDao> dao)
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
-            if (dao == null) return new List<TDto>();
             return Mapper<MapperGuid>.Instance.MapList<TDao, TDto>(dao);
         }
 
-        public static List<TDto> MapList<TDao, TDto>(this IEnumerable<TDao> dao)
+        public static List<TDto>? MapList<TDao, TDto>(this IEnumerable<TDao> dao)
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
-            if (dao == null) return new List<TDto>();
             return Mapper<MapperGuid>.Instance.MapList<TDao, TDto>(dao);
         }
 
@@ -62,8 +56,7 @@ namespace Quadarax.Foundation.Core.Data.Mapper
             where TDao : class, IDao<Guid>, new()
             where TDto : class, IDto, new()
         {
-            if (dto == null) return new List<TDao>().AsQueryable();
-            return Mapper<MapperGuid>.Instance.MapList<TDto, TDao>(dto.AsQueryable()).AsQueryable();
+            return (Mapper<MapperGuid>.Instance.MapList<TDto, TDao>(dto?.AsQueryable()) ?? throw new InvalidOperationException()).AsQueryable();
         }
 
     }

+ 21 - 7
qdr.fnd.core.data/Repository/EntityRepository.cs

@@ -16,7 +16,7 @@ namespace Quadarax.Foundation.Core.Data.Repository
         where TKey : IEquatable<TKey>
     {
         private IUnitOfWork<DataDomain> _unitOfWork;
-        private DbSet<TEntity> DbSetInstance => _unitOfWork.Context.GetDbSet<DbSet<TEntity>>();
+        private DbSet<TEntity>? DbSetInstance => _unitOfWork.Context.GetDbSet<DbSet<TEntity>>();
         protected DataDomain Context => _unitOfWork.Context;
         
         protected IList<string> DefaultIncludes { get; }
@@ -30,21 +30,26 @@ namespace Quadarax.Foundation.Core.Data.Repository
 
         protected virtual IQueryable<TEntity> OnQuery(IPaging paging,bool usingUncommited=false)
         {
-            var local = DbSetInstance.Local.Page(paging.IsDisabled ? (int?) null : paging.Page, paging.PageSize).AsQueryable();
-            if (local.Any() && usingUncommited)
+            var local = DbSetInstance?.Local.Page(paging.IsDisabled ? (int?) null : paging.Page, paging.PageSize).AsQueryable();
+            if (local !=null && local.Any() && usingUncommited)
             {
                 return local.MultiInclude(DefaultIncludes.ToArray());
             }
-
+            if (DbSetInstance == null)
+                throw new InvalidOperationException("DbSet is null");
             return DbSetInstance.Page(paging.IsDisabled ? (int?) null : paging.Page, paging.PageSize).MultiInclude(DefaultIncludes.ToArray());
         }
 
         public IQueryable<TEntity> Query(IPaging paging, bool usingUncomited = false)
         {
-            return OnQuery(paging, usingUncomited);
+            var query = OnQuery(paging, usingUncomited);
+            if (query== null)
+                throw new InvalidOperationException("DbSet is null");
+
+            return query;
         }
 
-        public virtual TEntity Get(TKey id)
+        public virtual TEntity? Get(TKey id)
         {
             return Query(Paging.NoPaging).MultiInclude(DefaultIncludes.ToArray()).FirstOrDefault(x => Equals(x.Id, id));
         }
@@ -67,12 +72,19 @@ namespace Quadarax.Foundation.Core.Data.Repository
 
         public virtual TEntity New()
         {
+            if (DbSetInstance == null)
+                throw new InvalidOperationException("DbSet is null");
             return DbSetInstance.Add(new TEntity()).Entity;
         }
 
         public virtual bool Remove(TKey id)
         {
-            DbSetInstance.Remove(Get(id));
+            if (DbSetInstance == null)
+                throw new InvalidOperationException("DbSet is null");
+            var entity = Get(id);
+            if (entity == null)
+                return false;
+            DbSetInstance.Remove(entity);
             return true;
         }
 
@@ -83,6 +95,8 @@ namespace Quadarax.Foundation.Core.Data.Repository
 
         public virtual bool Remove(TEntity entity)
         {
+            if (DbSetInstance == null)
+                throw new InvalidOperationException("DbSet is null");
             DbSetInstance.Remove(entity);
             return true;
         }

+ 52 - 34
qdr.fnd.core.data/qdr.fnd.core.data.csproj

@@ -1,38 +1,56 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
-  <PropertyGroup>
-    <TargetFramework>net7.0</TargetFramework>
-    <SignAssembly>true</SignAssembly>
-    <AssemblyOriginatorKeyFile>..\bo_strong_key_pair.snk</AssemblyOriginatorKeyFile>
-    <DelaySign>false</DelaySign>
-    <RootNamespace>Quadarax.Foundation.Core.Data</RootNamespace>
-    <ApplicationIcon>..\quadarax_dll.ico</ApplicationIcon>
-    <Title>Quadarax.Foundation.Core.Data</Title>
-    <Authors>Dalibor Votruba</Authors>
-    <Company>Quadarax</Company>
-    <Product>Quadarax.Foundation</Product>
-    <Description>Quadarax.Foundation.Core.Data - data layer foundation library</Description>
-    <Copyright>Copyright © 2023 Quadarax</Copyright>
-    <PackageIcon>quadarax_dll.png</PackageIcon>
-    <PackageTags>QDR;FND;CORE;DATA;DAO</PackageTags>
-    <AssemblyVersion>0.0.1.0</AssemblyVersion>
-    <FileVersion>0.0.1.0</FileVersion>
-    <Version>0.0.1.0-alpha</Version>
-    <Nullable>enable</Nullable>
-  </PropertyGroup>
-
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <SignAssembly>true</SignAssembly>
+    <AssemblyOriginatorKeyFile>..\bo_strong_key_pair.snk</AssemblyOriginatorKeyFile>
+    <DelaySign>false</DelaySign>
+    <RootNamespace>Quadarax.Foundation.Core.Data</RootNamespace>
+    <ApplicationIcon>..\quadarax_dll.ico</ApplicationIcon>
+    <Title>Quadarax.Foundation.Core.Data</Title>
+    <Authors>Dalibor Votruba</Authors>
+    <Company>Quadarax</Company>
+    <Product>Quadarax.Foundation</Product>
+    <Description>Quadarax.Foundation.Core.Data - data layer foundation library</Description>
+    <Copyright>Copyright © 2023 Quadarax</Copyright>
+    <PackageIcon>quadarax_dll.png</PackageIcon>
+    <PackageTags>QDR;FND;CORE;DATA;DAO</PackageTags>
+    <AssemblyVersion>0.0.2.0</AssemblyVersion>
+    <FileVersion>0.0.2.0</FileVersion>
+    <Version>0.0.2.0-alpha</Version>
+    <Nullable>enable</Nullable>
+    <PackageReadmeFile>releasenotes.md</PackageReadmeFile>
+    <PackageReleaseNotes>
+      Date:24.3.2024
+      - update dependencies packages (qdr.fnd.core)
+    </PackageReleaseNotes>
+  </PropertyGroup>
+
   <ItemGroup>
-    <None Include="..\quadarax_dll.png">
+    <Content Include="releasenotes.md">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
+  <ItemGroup>
+    <Content Include="..\quadarax_dll.png">
+      <Pack>True</Pack>
+      <PackagePath>\</PackagePath>
+    </Content>
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
+    <PackageReference Include="qdr.fnd.core" Version="0.0.4-alpha" />
+    <PackageReference Include="qdr.fnd.core.data.itfc" Version="0.0.2-alpha" />
+    <PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Update="releasenotes.md">
       <Pack>True</Pack>
       <PackagePath>\</PackagePath>
     </None>
-  </ItemGroup>
-
-  <ItemGroup>
-    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
-    <PackageReference Include="qdr.fnd.core" Version="0.0.1-alpha" />
-    <PackageReference Include="qdr.fnd.core.data.itfc" Version="0.0.1-alpha" />
-    <PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
-  </ItemGroup>
-
-</Project>
+  </ItemGroup>
+
+</Project>

+ 15 - 0
qdr.fnd.core.data/releasenotes.md

@@ -0,0 +1,15 @@
+# Quadarax.Foundation.Core.Data * Release notes
+Ordered by version descending
+
+
+## 0.0.2.0
+Date:__24.3.2024__
+- update dependency to qdr.fnd.core v.0.0.4.0
+- fix quality CA
+- minor fixes
+---
+## 0.0.1.0
+Date:__1.9.2023__
+- initial version
+---
+---