mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-07-30 17:30:40 +00:00
Esiur CLI
This commit is contained in:
@@ -60,9 +60,20 @@ public class EntityStore : IStore
|
||||
|
||||
public AsyncReply<IResource> Get(string path)
|
||||
{
|
||||
var p = path.Split('/');
|
||||
var ti = TypesByName[p[0]];
|
||||
var id = Convert.ChangeType(p[1], ti.PrimaryKey.PropertyType);
|
||||
var p = path.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (p.Length != 2 || !TypesByName.TryGetValue(p[0], out var ti))
|
||||
return new AsyncReply<IResource>(null);
|
||||
|
||||
object id;
|
||||
try
|
||||
{
|
||||
id = Convert.ChangeType(p[1], ti.PrimaryKey.PropertyType);
|
||||
}
|
||||
catch (Exception) when (
|
||||
ti.PrimaryKey.PropertyType != typeof(string))
|
||||
{
|
||||
return new AsyncReply<IResource>(null);
|
||||
}
|
||||
|
||||
// Get db
|
||||
using (var db = Getter())
|
||||
@@ -97,8 +108,6 @@ public class EntityStore : IStore
|
||||
|
||||
//var refs = ent.References.ToList();
|
||||
|
||||
db.Dispose();
|
||||
|
||||
return new AsyncReply<IResource>(res);
|
||||
}
|
||||
}
|
||||
@@ -223,7 +232,7 @@ public class EntityStore : IStore
|
||||
|
||||
internal DbContextOptions Options { get; set; }
|
||||
|
||||
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext? context = null)
|
||||
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||
{
|
||||
if (operation == ResourceOperation.Initialize)// SystemInitialized && DbContext != null)
|
||||
{
|
||||
@@ -247,7 +256,7 @@ public class EntityStore : IStore
|
||||
TypesByName.Clear();
|
||||
TypesByType.Clear();
|
||||
|
||||
var context = Getter();
|
||||
using var context = Getter();
|
||||
|
||||
var types = context.Model.GetEntityTypes();
|
||||
foreach (var t in types)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<Product>Esiur Entity Framework Extension</Product>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageId>Esiur.Stores.EntityCore</PackageId>
|
||||
<Version>1.3.4</Version>
|
||||
<Version>3.0.0</Version>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
@@ -23,7 +23,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -129,7 +129,7 @@ public static class EsiurExtensions
|
||||
var entity = dbSet.Add((T)res);
|
||||
await entity.Context.SaveChangesAsync();
|
||||
|
||||
var id = store.TypesByType[typeof(T)].PrimaryKey.GetValue(resource);
|
||||
var id = store.TypesByType[typeof(T)].PrimaryKey.GetValue(res);
|
||||
|
||||
var resourceContext = manager == null
|
||||
? null
|
||||
@@ -178,12 +178,25 @@ public static class EsiurExtensions
|
||||
extension = new EsiurExtensionOptions(store);
|
||||
}
|
||||
|
||||
if (getter != null)
|
||||
extension.Store.Getter = getter;
|
||||
|
||||
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);
|
||||
|
||||
return optionsBuilder;
|
||||
|
||||
}
|
||||
|
||||
public static DbContextOptionsBuilder<TContext> UseEsiur<TContext>(
|
||||
this DbContextOptionsBuilder<TContext> optionsBuilder,
|
||||
EntityStore store,
|
||||
Func<DbContext> getter = null)
|
||||
where TContext : DbContext
|
||||
{
|
||||
UseEsiur((DbContextOptionsBuilder)optionsBuilder, store, getter);
|
||||
return optionsBuilder;
|
||||
}
|
||||
|
||||
//public static DbContextOptionsBuilder<TContext> UseEsiur<TContext>(
|
||||
// this DbContextOptionsBuilder<TContext> optionsBuilder,
|
||||
// //DbContext context,
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/esiur/esiur-dotnet/</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>1.5.6</Version>
|
||||
<Version>3.0.0</Version>
|
||||
<PackageId>Esiur.Stores.MongoDB</PackageId>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
|
||||
Reference in New Issue
Block a user