This commit is contained in:
@@ -2983,7 +2983,7 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
schema = ReadSchema(tableName, owner)
|
schema = ReadSchema(tableName, owner)
|
||||||
.Where(x => x.Name != null)
|
.Where(x => x.Name != null)
|
||||||
.DistinctBy(x => x.Name)
|
.DistinctBy(x => x.Name.ToLower())
|
||||||
.ToDictionary(k => k.Name.ToLower(), k => k);
|
.ToDictionary(k => k.Name.ToLower(), k => k);
|
||||||
|
|
||||||
Schema[tableName.ToLower()] = schema;
|
Schema[tableName.ToLower()] = schema;
|
||||||
@@ -13538,10 +13538,16 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
else if (Type == typeof(string) && val.GetType() == typeof(Guid))
|
else if (Type == typeof(string) && val.GetType() == typeof(Guid))
|
||||||
return val.ToString();
|
return val.ToString();
|
||||||
else if (Type == typeof(Guid) && val.GetType() == typeof(string))
|
else if (Type == typeof(Guid))
|
||||||
{
|
{
|
||||||
Guid g;
|
if (val.GetType() == typeof(byte[]))
|
||||||
return Guid.TryParse((string)val, out g) ? g : Guid.Empty;
|
return new Guid((byte[])val);
|
||||||
|
else if (val.GetType() == typeof(string))
|
||||||
|
{
|
||||||
|
Guid g;
|
||||||
|
return Guid.TryParse((string)val, out g) ? g : Guid.Empty;
|
||||||
|
}
|
||||||
|
else return (nullable) ? null : (object)Guid.Empty;
|
||||||
}
|
}
|
||||||
else if (!typeof(IConvertible).IsAssignableFrom(type) && (IsDataContract || (!type.IsValueType && val is IDictionary<string, object>)))
|
else if (!typeof(IConvertible).IsAssignableFrom(type) && (IsDataContract || (!type.IsValueType && val is IDictionary<string, object>)))
|
||||||
return val.Map(type);
|
return val.Map(type);
|
||||||
@@ -13995,10 +14001,10 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
MakeQueryWhere(mapper, query);
|
MakeQueryWhere(mapper, query);
|
||||||
|
|
||||||
|
bool any = false;
|
||||||
|
|
||||||
if (_changedFields.Any())
|
if (_changedFields.Any())
|
||||||
{
|
{
|
||||||
bool any = false;
|
|
||||||
|
|
||||||
foreach (var cf in _changedFields)
|
foreach (var cf in _changedFields)
|
||||||
{
|
{
|
||||||
var cn = mapper.PropertyMap[cf.Key];
|
var cn = mapper.PropertyMap[cf.Key];
|
||||||
@@ -14018,12 +14024,32 @@ namespace DynamORM
|
|||||||
query.Values(cn, cf.Value);
|
query.Values(cn, cf.Value);
|
||||||
any = true;
|
any = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!any)
|
|
||||||
query.Set(x => this);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
query.Set(x => this);
|
if (!any)
|
||||||
|
foreach (var pmk in mapper.ColumnsMap)
|
||||||
|
{
|
||||||
|
var pm = pmk.Value;
|
||||||
|
var val = pm.Get(this);
|
||||||
|
var cn = pm.Name;
|
||||||
|
|
||||||
|
if (pm.Ignore)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (pm.Column != null)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(pm.Column.Name))
|
||||||
|
cn = pm.Column.Name;
|
||||||
|
|
||||||
|
if (pm.Column.IsKey)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!pm.Column.AllowNull && val == null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
query.Values(cn, val);
|
||||||
|
}
|
||||||
|
|
||||||
if (query.Execute() == 0)
|
if (query.Execute() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<Description>Dynamic Object-Relational Mapping library.</Description>
|
<Description>Dynamic Object-Relational Mapping library.</Description>
|
||||||
<Copyright>Copyright © RUSSEK Software 2012-2019</Copyright>
|
<Copyright>Copyright © RUSSEK Software 2012-2019</Copyright>
|
||||||
<Company>RUSSEK Software</Company>
|
<Company>RUSSEK Software</Company>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>DynamORM.Tests</RootNamespace>
|
<RootNamespace>DynamORM.Tests</RootNamespace>
|
||||||
<AssemblyName>DynamORM.Tests</AssemblyName>
|
<AssemblyName>DynamORM.Tests</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||||
|
|||||||
2
DynamORM.Tests/Properties/Resources.Designer.cs
generated
2
DynamORM.Tests/Properties/Resources.Designer.cs
generated
@@ -19,7 +19,7 @@ namespace DynamORM.Tests.Properties {
|
|||||||
// class via a tool like ResGen or Visual Studio.
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// with the /str option, or rebuild your VS project.
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
internal class Resources {
|
||||||
|
|||||||
@@ -1524,7 +1524,7 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
schema = ReadSchema(tableName, owner)
|
schema = ReadSchema(tableName, owner)
|
||||||
.Where(x => x.Name != null)
|
.Where(x => x.Name != null)
|
||||||
.DistinctBy(x => x.Name)
|
.DistinctBy(x => x.Name.ToLower())
|
||||||
.ToDictionary(k => k.Name.ToLower(), k => k);
|
.ToDictionary(k => k.Name.ToLower(), k => k);
|
||||||
|
|
||||||
Schema[tableName.ToLower()] = schema;
|
Schema[tableName.ToLower()] = schema;
|
||||||
|
|||||||
@@ -67,10 +67,27 @@ namespace DynamORM.Helpers
|
|||||||
{
|
{
|
||||||
ParameterExpression param = Expression.Parameter(typeof(InvokeMemberBinder), "o");
|
ParameterExpression param = Expression.Parameter(typeof(InvokeMemberBinder), "o");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Expression.Lambda<Func<InvokeMemberBinder, IList<Type>>>(
|
||||||
|
Expression.TypeAs(
|
||||||
|
Expression.Field(
|
||||||
|
Expression.TypeAs(param, binderType), "typeArguments"),
|
||||||
|
typeof(IList<Type>)), param).Compile();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertyInfo prop = binderType.GetProperty("TypeArguments");
|
||||||
|
|
||||||
|
if (!prop.CanRead)
|
||||||
|
return null;
|
||||||
|
|
||||||
return Expression.Lambda<Func<InvokeMemberBinder, IList<Type>>>(
|
return Expression.Lambda<Func<InvokeMemberBinder, IList<Type>>>(
|
||||||
Expression.TypeAs(
|
Expression.TypeAs(
|
||||||
Expression.Field(
|
Expression.Property(
|
||||||
Expression.TypeAs(param, binderType), "typeArguments"),
|
Expression.TypeAs(param, binderType), prop.Name),
|
||||||
typeof(IList<Type>)), param).Compile();
|
typeof(IList<Type>)), param).Compile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,6 +144,14 @@ namespace DynamORM.Helpers
|
|||||||
// If this was a success get and return it's value
|
// If this was a success get and return it's value
|
||||||
if (field != null)
|
if (field != null)
|
||||||
return field.GetValue(binder) as IList<Type>;
|
return field.GetValue(binder) as IList<Type>;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PropertyInfo prop = binder.GetType().GetProperty("TypeArguments");
|
||||||
|
|
||||||
|
// If we have a property, return it's value
|
||||||
|
if (prop != null)
|
||||||
|
return prop.GetValue(binder, null) as IList<Type>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -234,10 +234,16 @@ namespace DynamORM.Mapper
|
|||||||
}
|
}
|
||||||
else if (Type == typeof(string) && val.GetType() == typeof(Guid))
|
else if (Type == typeof(string) && val.GetType() == typeof(Guid))
|
||||||
return val.ToString();
|
return val.ToString();
|
||||||
else if (Type == typeof(Guid) && val.GetType() == typeof(string))
|
else if (Type == typeof(Guid))
|
||||||
{
|
{
|
||||||
Guid g;
|
if (val.GetType() == typeof(byte[]))
|
||||||
return Guid.TryParse((string)val, out g) ? g : Guid.Empty;
|
return new Guid((byte[])val);
|
||||||
|
else if (val.GetType() == typeof(string))
|
||||||
|
{
|
||||||
|
Guid g;
|
||||||
|
return Guid.TryParse((string)val, out g) ? g : Guid.Empty;
|
||||||
|
}
|
||||||
|
else return (nullable) ? null : (object)Guid.Empty;
|
||||||
}
|
}
|
||||||
else if (!typeof(IConvertible).IsAssignableFrom(type) && (IsDataContract || (!type.IsValueType && val is IDictionary<string, object>)))
|
else if (!typeof(IConvertible).IsAssignableFrom(type) && (IsDataContract || (!type.IsValueType && val is IDictionary<string, object>)))
|
||||||
return val.Map(type);
|
return val.Map(type);
|
||||||
|
|||||||
@@ -126,13 +126,12 @@ namespace DynamORM.Objects
|
|||||||
var mapper = DynamicMapperCache.GetMapper(t);
|
var mapper = DynamicMapperCache.GetMapper(t);
|
||||||
using (var query = db.Update(t))
|
using (var query = db.Update(t))
|
||||||
{
|
{
|
||||||
|
|
||||||
MakeQueryWhere(mapper, query);
|
MakeQueryWhere(mapper, query);
|
||||||
|
|
||||||
|
bool any = false;
|
||||||
|
|
||||||
if (_changedFields.Any())
|
if (_changedFields.Any())
|
||||||
{
|
{
|
||||||
bool any = false;
|
|
||||||
|
|
||||||
foreach (var cf in _changedFields)
|
foreach (var cf in _changedFields)
|
||||||
{
|
{
|
||||||
var cn = mapper.PropertyMap[cf.Key];
|
var cn = mapper.PropertyMap[cf.Key];
|
||||||
@@ -152,12 +151,32 @@ namespace DynamORM.Objects
|
|||||||
query.Values(cn, cf.Value);
|
query.Values(cn, cf.Value);
|
||||||
any = true;
|
any = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!any)
|
|
||||||
query.Set(x => this);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
query.Set(x => this);
|
if (!any)
|
||||||
|
foreach (var pmk in mapper.ColumnsMap)
|
||||||
|
{
|
||||||
|
var pm = pmk.Value;
|
||||||
|
var val = pm.Get(this);
|
||||||
|
var cn = pm.Name;
|
||||||
|
|
||||||
|
if (pm.Ignore)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (pm.Column != null)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(pm.Column.Name))
|
||||||
|
cn = pm.Column.Name;
|
||||||
|
|
||||||
|
if (pm.Column.IsKey)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!pm.Column.AllowNull && val == null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
query.Values(cn, val);
|
||||||
|
}
|
||||||
|
|
||||||
if (query.Execute() == 0)
|
if (query.Execute() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user