This commit is contained in:
@@ -1524,7 +1524,7 @@ namespace DynamORM
|
||||
{
|
||||
schema = ReadSchema(tableName, owner)
|
||||
.Where(x => x.Name != null)
|
||||
.DistinctBy(x => x.Name)
|
||||
.DistinctBy(x => x.Name.ToLower())
|
||||
.ToDictionary(k => k.Name.ToLower(), k => k);
|
||||
|
||||
Schema[tableName.ToLower()] = schema;
|
||||
|
||||
@@ -67,10 +67,27 @@ namespace DynamORM.Helpers
|
||||
{
|
||||
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>>>(
|
||||
Expression.TypeAs(
|
||||
Expression.Field(
|
||||
Expression.TypeAs(param, binderType), "typeArguments"),
|
||||
Expression.Property(
|
||||
Expression.TypeAs(param, binderType), prop.Name),
|
||||
typeof(IList<Type>)), param).Compile();
|
||||
}
|
||||
}
|
||||
@@ -127,6 +144,14 @@ namespace DynamORM.Helpers
|
||||
// If this was a success get and return it's value
|
||||
if (field != null)
|
||||
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
|
||||
{
|
||||
|
||||
@@ -234,10 +234,16 @@ namespace DynamORM.Mapper
|
||||
}
|
||||
else if (Type == typeof(string) && val.GetType() == typeof(Guid))
|
||||
return val.ToString();
|
||||
else if (Type == typeof(Guid) && val.GetType() == typeof(string))
|
||||
else if (Type == typeof(Guid))
|
||||
{
|
||||
Guid g;
|
||||
return Guid.TryParse((string)val, out g) ? g : Guid.Empty;
|
||||
if (val.GetType() == typeof(byte[]))
|
||||
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>)))
|
||||
return val.Map(type);
|
||||
|
||||
@@ -126,13 +126,12 @@ namespace DynamORM.Objects
|
||||
var mapper = DynamicMapperCache.GetMapper(t);
|
||||
using (var query = db.Update(t))
|
||||
{
|
||||
|
||||
MakeQueryWhere(mapper, query);
|
||||
|
||||
bool any = false;
|
||||
|
||||
if (_changedFields.Any())
|
||||
{
|
||||
bool any = false;
|
||||
|
||||
foreach (var cf in _changedFields)
|
||||
{
|
||||
var cn = mapper.PropertyMap[cf.Key];
|
||||
@@ -152,12 +151,32 @@ namespace DynamORM.Objects
|
||||
query.Values(cn, cf.Value);
|
||||
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)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user