mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 21:13:13 +00:00
VarList
This commit is contained in:
@ -33,6 +33,8 @@ using Esiur.Proxy;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System.Reflection;
|
||||
using Esiur.Security.Authority;
|
||||
using System.Collections;
|
||||
|
||||
namespace Esiur.Stores.EntityCore;
|
||||
public class EntityStore : IStore
|
||||
@ -63,30 +65,42 @@ public class EntityStore : IStore
|
||||
var id = Convert.ChangeType(p[1], ti.PrimaryKey.PropertyType);
|
||||
|
||||
// Get db
|
||||
var db = Getter();
|
||||
var res = db.Find(ti.Type.ClrType, id);
|
||||
|
||||
if (res == null)
|
||||
using (var db = Getter())
|
||||
{
|
||||
return new AsyncReply<IResource>(null);
|
||||
|
||||
//var rt = new AsyncReply<IResource>();
|
||||
//rt.TriggerError(new AsyncException(ErrorType.Management,
|
||||
// (ushort)ExceptionCode.ResourceNotFound, "Resource not found."));
|
||||
//return rt;
|
||||
var res = db.Find(ti.Type.ClrType, id) as IResource;
|
||||
|
||||
|
||||
if (res == null)
|
||||
{
|
||||
return new AsyncReply<IResource>(null);
|
||||
|
||||
//var rt = new AsyncReply<IResource>();
|
||||
//rt.TriggerError(new AsyncException(ErrorType.Management,
|
||||
// (ushort)ExceptionCode.ResourceNotFound, "Resource not found."));
|
||||
//return rt;
|
||||
}
|
||||
|
||||
|
||||
// load navigation properties
|
||||
var ent = db.Entry(res);
|
||||
|
||||
foreach (var rf in ent.References)
|
||||
{
|
||||
rf.Load();
|
||||
}
|
||||
|
||||
foreach(var col in ent.Collections)
|
||||
{
|
||||
col.Load();
|
||||
}
|
||||
|
||||
//var refs = ent.References.ToList();
|
||||
|
||||
db.Dispose();
|
||||
|
||||
return new AsyncReply<IResource>(res);
|
||||
}
|
||||
|
||||
// load navigation properties
|
||||
var ent = db.Entry(res);
|
||||
foreach (var rf in ent.References)
|
||||
rf.Load();
|
||||
|
||||
foreach(var nav in ent.Navigations)
|
||||
nav.Load();
|
||||
|
||||
//var refs = ent.References.ToList();
|
||||
|
||||
return new AsyncReply<IResource>(res as IResource);
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Put(IResource resource)
|
||||
|
@ -22,7 +22,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
|
||||
<PackageReference Include="System.Collections" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -47,6 +47,10 @@ public static class EsiurExtensions
|
||||
|
||||
//}
|
||||
|
||||
public static DbSet<object> SetByType(this DbContext context, Type t)
|
||||
{
|
||||
return (DbSet<object>)context.GetType().GetMethod("Set").MakeGenericMethod(t).Invoke(context, new object[0]);
|
||||
}
|
||||
|
||||
public static T AddResource<T>(this DbSet<T> dbSet, T resource) where T : class, IResource
|
||||
=> AddResourceAsync(dbSet, resource).Wait();
|
||||
|
@ -61,8 +61,10 @@ public class EsiurProxyRewrite : IModelFinalizingConvention
|
||||
|
||||
var cache = options.Store.GetById(entityType.ClrType, id);
|
||||
|
||||
if (cache != null)
|
||||
if (cache != null && cache.Instance != null)
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
|
||||
if (Codec.ImplementsInterface(entityType.ClrType, typeof(IResource)))
|
||||
{
|
||||
|
Reference in New Issue
Block a user