This commit is contained in:
File diff suppressed because it is too large
Load Diff
12
DynamORM.sln
12
DynamORM.sln
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamORM.Tests", "DynamORM.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AmalgamationTool", "AmalgamationTool\AmalgamationTool.csproj", "{A64D2052-D0CD-488E-BF05-E5952615D926}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AmalgamationTool", "AmalgamationTool\AmalgamationTool.csproj", "{A64D2052-D0CD-488E-BF05-E5952615D926}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester", "Tester\Tester.csproj", "{F747AA57-BEA7-4FB8-B371-546296789AEF}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -47,6 +49,16 @@ Global
|
|||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.Build.0 = Release|x86
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.ActiveCfg = Release|x86
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.ActiveCfg = Release|x86
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.Build.0 = Release|x86
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.Build.0 = Release|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|Any CPU.ActiveCfg = Release|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -190,7 +190,13 @@ namespace DynamORM.Builders.Implementation
|
|||||||
{
|
{
|
||||||
foreach (var con in dict)
|
foreach (var con in dict)
|
||||||
if (!mapper.Ignored.Contains(con.Key))
|
if (!mapper.Ignored.Contains(con.Key))
|
||||||
Insert(mapper.PropertyMap.TryGetValue(con.Key) ?? con.Key, con.Value);
|
{
|
||||||
|
var colName = mapper.PropertyMap.TryGetValue(con.Key) ?? con.Key;
|
||||||
|
var propMap = mapper.ColumnsMap.TryGetValue(colName.ToLower());
|
||||||
|
|
||||||
|
if (propMap == null || propMap.Column == null || !propMap.Column.IsNoInsert)
|
||||||
|
Insert(colName, con.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
foreach (var con in dict)
|
foreach (var con in dict)
|
||||||
|
|||||||
@@ -134,7 +134,9 @@ namespace DynamORM.Builders.Implementation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Values(colName, con.Value);
|
var propMap = mapper.ColumnsMap.TryGetValue(colName.ToLower());
|
||||||
|
if (propMap == null || propMap.Column == null || !propMap.Column.IsNoUpdate)
|
||||||
|
Values(colName, con.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -349,43 +349,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
PrepareBatchInsert<T>(mapper, cmd, parameters);
|
||||||
DynamicPropertyInvoker currentprop = null;
|
|
||||||
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
|
||||||
int ord = 0;
|
|
||||||
|
|
||||||
var ib = Insert<T>()
|
|
||||||
.SetVirtualMode(true)
|
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
|
||||||
.CreateParameterAction((p, cp) =>
|
|
||||||
{
|
|
||||||
parameters[cp] = temp[p.Name];
|
|
||||||
parameters[cp].InsertCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
|
||||||
{
|
|
||||||
Name = cp.ParameterName,
|
|
||||||
Type = cp.DbType,
|
|
||||||
Ordinal = ord++,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var prop in mapper.PropertyMap)
|
|
||||||
if (!mapper.Ignored.Contains(prop.Key))
|
|
||||||
{
|
|
||||||
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
|
||||||
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
|
||||||
|
|
||||||
if (currentprop.Ignore)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (currentprop.Get != null)
|
|
||||||
ib.Insert(col, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
ib.FillCommand(cmd);
|
|
||||||
|
|
||||||
// Cache command
|
|
||||||
mapper.InsertCommandText = cmd.CommandText;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
@@ -483,48 +447,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
PrepareBatchUpdate<T>(mapper, cmd, parameters);
|
||||||
DynamicPropertyInvoker currentprop = null;
|
|
||||||
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
|
||||||
int ord = 0;
|
|
||||||
|
|
||||||
var ib = Update<T>()
|
|
||||||
.SetVirtualMode(true)
|
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
|
||||||
.CreateParameterAction((p, cp) =>
|
|
||||||
{
|
|
||||||
parameters[cp] = temp[p.Name];
|
|
||||||
parameters[cp].UpdateCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
|
||||||
{
|
|
||||||
Name = cp.ParameterName,
|
|
||||||
Type = cp.DbType,
|
|
||||||
Ordinal = ord++,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var prop in mapper.PropertyMap)
|
|
||||||
if (!mapper.Ignored.Contains(prop.Key))
|
|
||||||
{
|
|
||||||
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
|
||||||
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
|
||||||
|
|
||||||
if (currentprop.Ignore)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (currentprop.Get != null)
|
|
||||||
{
|
|
||||||
if (currentprop.Column != null && currentprop.Column.IsKey)
|
|
||||||
ib.Where(col, null);
|
|
||||||
else
|
|
||||||
ib.Values(col, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ib.FillCommand(cmd);
|
|
||||||
|
|
||||||
// Cache command
|
|
||||||
mapper.UpdateCommandText = cmd.CommandText;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
@@ -593,48 +516,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
PrepareBatchUpdate<T>(mapper, cmdUp, parametersUp);
|
||||||
DynamicPropertyInvoker currentprop = null;
|
|
||||||
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
|
||||||
int ord = 0;
|
|
||||||
|
|
||||||
var ib = Update<T>()
|
|
||||||
.SetVirtualMode(true)
|
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
|
||||||
.CreateParameterAction((p, cp) =>
|
|
||||||
{
|
|
||||||
parametersUp[cp] = temp[p.Name];
|
|
||||||
parametersUp[cp].UpdateCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
|
||||||
{
|
|
||||||
Name = cp.ParameterName,
|
|
||||||
Type = cp.DbType,
|
|
||||||
Ordinal = ord++,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var prop in mapper.PropertyMap)
|
|
||||||
if (!mapper.Ignored.Contains(prop.Key))
|
|
||||||
{
|
|
||||||
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
|
||||||
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
|
||||||
|
|
||||||
if (currentprop.Ignore)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (currentprop.Get != null)
|
|
||||||
{
|
|
||||||
if (currentprop.Column != null && currentprop.Column.IsKey)
|
|
||||||
ib.Where(col, null);
|
|
||||||
else
|
|
||||||
ib.Values(col, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ib.FillCommand(cmdUp);
|
|
||||||
|
|
||||||
// Cache command
|
|
||||||
mapper.UpdateCommandText = cmdUp.CommandText;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Update
|
#endregion Update
|
||||||
|
|
||||||
@@ -659,43 +541,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
PrepareBatchInsert<T>(mapper, cmdIn, parametersIn);
|
||||||
DynamicPropertyInvoker currentprop = null;
|
|
||||||
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
|
||||||
int ord = 0;
|
|
||||||
|
|
||||||
var ib = Insert<T>()
|
|
||||||
.SetVirtualMode(true)
|
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
|
||||||
.CreateParameterAction((p, cp) =>
|
|
||||||
{
|
|
||||||
parametersIn[cp] = temp[p.Name];
|
|
||||||
parametersIn[cp].InsertCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
|
||||||
{
|
|
||||||
Name = cp.ParameterName,
|
|
||||||
Type = cp.DbType,
|
|
||||||
Ordinal = ord++,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var prop in mapper.PropertyMap)
|
|
||||||
if (!mapper.Ignored.Contains(prop.Key))
|
|
||||||
{
|
|
||||||
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
|
||||||
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
|
||||||
|
|
||||||
if (currentprop.Ignore)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (currentprop.Get != null)
|
|
||||||
ib.Insert(col, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
ib.FillCommand(cmdIn);
|
|
||||||
|
|
||||||
// Cache command
|
|
||||||
mapper.InsertCommandText = cmdIn.CommandText;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Insert
|
#endregion Insert
|
||||||
|
|
||||||
@@ -796,46 +642,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
PrepareBatchDelete<T>(mapper, cmd, parameters);
|
||||||
DynamicPropertyInvoker currentprop = null;
|
|
||||||
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
|
||||||
int ord = 0;
|
|
||||||
|
|
||||||
var ib = Delete<T>()
|
|
||||||
.SetVirtualMode(true)
|
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
|
||||||
.CreateParameterAction((p, cp) =>
|
|
||||||
{
|
|
||||||
parameters[cp] = temp[p.Name];
|
|
||||||
parameters[cp].DeleteCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
|
||||||
{
|
|
||||||
Name = cp.ParameterName,
|
|
||||||
Type = cp.DbType,
|
|
||||||
Ordinal = ord++,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var prop in mapper.PropertyMap)
|
|
||||||
if (!mapper.Ignored.Contains(prop.Key))
|
|
||||||
{
|
|
||||||
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
|
||||||
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
|
||||||
|
|
||||||
if (currentprop.Ignore)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (currentprop.Get != null)
|
|
||||||
{
|
|
||||||
if (currentprop.Column != null && currentprop.Column.IsKey)
|
|
||||||
ib.Where(col, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ib.FillCommand(cmd);
|
|
||||||
|
|
||||||
// Cache command
|
|
||||||
mapper.DeleteCommandText = cmd.CommandText;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
@@ -865,6 +672,190 @@ namespace DynamORM
|
|||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchInsert<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
DynamicPropertyInvoker currentprop = null;
|
||||||
|
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
|
var schema = this.GetSchema<T>();
|
||||||
|
int ord = 0;
|
||||||
|
|
||||||
|
var ib = Insert<T>()
|
||||||
|
.SetVirtualMode(true)
|
||||||
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
|
.CreateParameterAction((p, cp) =>
|
||||||
|
{
|
||||||
|
parameters[cp] = temp[p.Name];
|
||||||
|
parameters[cp].InsertCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
||||||
|
{
|
||||||
|
Name = cp.ParameterName,
|
||||||
|
Type = cp.DbType,
|
||||||
|
Ordinal = ord++,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var prop in mapper.PropertyMap)
|
||||||
|
if (!mapper.Ignored.Contains(prop.Key))
|
||||||
|
{
|
||||||
|
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
||||||
|
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
||||||
|
|
||||||
|
if (currentprop.Ignore || (currentprop.Column != null && currentprop.Column.IsNoInsert))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (currentprop.Get != null)
|
||||||
|
ib.Insert(new DynamicColumn()
|
||||||
|
{
|
||||||
|
ColumnName = col,
|
||||||
|
Schema = schema == null ? null : schema.TryGetNullable(col.ToLower()),
|
||||||
|
Operator = DynamicColumn.CompareOperator.Eq,
|
||||||
|
Value = null,
|
||||||
|
VirtualColumn = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ib.FillCommand(cmd);
|
||||||
|
|
||||||
|
// Cache command
|
||||||
|
mapper.InsertCommandText = cmd.CommandText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchUpdate<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
DynamicPropertyInvoker currentprop = null;
|
||||||
|
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
|
var schema = this.GetSchema<T>();
|
||||||
|
int ord = 0;
|
||||||
|
|
||||||
|
var ib = Update<T>()
|
||||||
|
.SetVirtualMode(true)
|
||||||
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
|
.CreateParameterAction((p, cp) =>
|
||||||
|
{
|
||||||
|
parameters[cp] = temp[p.Name];
|
||||||
|
parameters[cp].UpdateCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
||||||
|
{
|
||||||
|
Name = cp.ParameterName,
|
||||||
|
Type = cp.DbType,
|
||||||
|
Ordinal = ord++,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var prop in mapper.PropertyMap)
|
||||||
|
if (!mapper.Ignored.Contains(prop.Key))
|
||||||
|
{
|
||||||
|
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
||||||
|
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
||||||
|
|
||||||
|
if (currentprop.Ignore)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (currentprop.Get != null)
|
||||||
|
{
|
||||||
|
var colS = schema == null ? null : schema.TryGetNullable(col.ToLower());
|
||||||
|
|
||||||
|
if (colS.HasValue)
|
||||||
|
{
|
||||||
|
if (colS.Value.IsKey)
|
||||||
|
ib.Where(new DynamicColumn()
|
||||||
|
{
|
||||||
|
ColumnName = col,
|
||||||
|
Schema = colS,
|
||||||
|
Operator = DynamicColumn.CompareOperator.Eq,
|
||||||
|
Value = null,
|
||||||
|
VirtualColumn = true,
|
||||||
|
});
|
||||||
|
else if (currentprop.Column == null || !currentprop.Column.IsNoUpdate)
|
||||||
|
ib.Values(new DynamicColumn()
|
||||||
|
{
|
||||||
|
ColumnName = col,
|
||||||
|
Schema = colS,
|
||||||
|
Operator = DynamicColumn.CompareOperator.Eq,
|
||||||
|
Value = null,
|
||||||
|
VirtualColumn = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (currentprop.Column != null && currentprop.Column.IsKey)
|
||||||
|
ib.Where(new DynamicColumn()
|
||||||
|
{
|
||||||
|
ColumnName = col,
|
||||||
|
Schema = colS,
|
||||||
|
Operator = DynamicColumn.CompareOperator.Eq,
|
||||||
|
Value = null,
|
||||||
|
VirtualColumn = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ib.FillCommand(cmd);
|
||||||
|
|
||||||
|
// Cache command
|
||||||
|
mapper.UpdateCommandText = cmd.CommandText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchDelete<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
DynamicPropertyInvoker currentprop = null;
|
||||||
|
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
|
var schema = this.GetSchema<T>();
|
||||||
|
int ord = 0;
|
||||||
|
|
||||||
|
var ib = Delete<T>()
|
||||||
|
.SetVirtualMode(true)
|
||||||
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
|
.CreateParameterAction((p, cp) =>
|
||||||
|
{
|
||||||
|
parameters[cp] = temp[p.Name];
|
||||||
|
parameters[cp].DeleteCommandParameter = new DynamicPropertyInvoker.ParameterSpec
|
||||||
|
{
|
||||||
|
Name = cp.ParameterName,
|
||||||
|
Type = cp.DbType,
|
||||||
|
Ordinal = ord++,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var prop in mapper.PropertyMap)
|
||||||
|
if (!mapper.Ignored.Contains(prop.Key))
|
||||||
|
{
|
||||||
|
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
||||||
|
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
||||||
|
|
||||||
|
if (currentprop.Ignore)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (currentprop.Get != null)
|
||||||
|
{
|
||||||
|
var colS = schema == null ? null : schema.TryGetNullable(col.ToLower());
|
||||||
|
|
||||||
|
if (colS != null)
|
||||||
|
{
|
||||||
|
if (colS.Value.IsKey)
|
||||||
|
ib.Where(new DynamicColumn()
|
||||||
|
{
|
||||||
|
ColumnName = col,
|
||||||
|
Schema = colS,
|
||||||
|
Operator = DynamicColumn.CompareOperator.Eq,
|
||||||
|
Value = null,
|
||||||
|
VirtualColumn = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (currentprop.Column != null && currentprop.Column.IsKey)
|
||||||
|
ib.Where(new DynamicColumn()
|
||||||
|
{
|
||||||
|
ColumnName = col,
|
||||||
|
Schema = colS,
|
||||||
|
Operator = DynamicColumn.CompareOperator.Eq,
|
||||||
|
Value = null,
|
||||||
|
VirtualColumn = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ib.FillCommand(cmd);
|
||||||
|
|
||||||
|
// Cache command
|
||||||
|
mapper.DeleteCommandText = cmd.CommandText;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion From/Insert/Update/Delete
|
#endregion From/Insert/Update/Delete
|
||||||
|
|
||||||
#region Schema
|
#region Schema
|
||||||
@@ -895,7 +886,7 @@ namespace DynamORM
|
|||||||
Dictionary<string, DynamicSchemaColumn> schema = null;
|
Dictionary<string, DynamicSchemaColumn> schema = null;
|
||||||
|
|
||||||
lock (SyncLock)
|
lock (SyncLock)
|
||||||
schema = Schema.TryGetValue(typeof(T).GetType().FullName) ??
|
schema = Schema.TryGetValue(typeof(T).FullName) ??
|
||||||
BuildAndCacheSchema(null, DynamicMapperCache.GetMapper<T>());
|
BuildAndCacheSchema(null, DynamicMapperCache.GetMapper<T>());
|
||||||
|
|
||||||
return schema;
|
return schema;
|
||||||
@@ -977,7 +968,8 @@ namespace DynamORM
|
|||||||
|
|
||||||
#region Type schema
|
#region Type schema
|
||||||
|
|
||||||
if (mapperSchema && !Schema.ContainsKey(mapper.Type.FullName))
|
if ((mapperSchema && !Schema.ContainsKey(mapper.Type.FullName)) ||
|
||||||
|
(schema == null && !mapper.Type.IsAnonymous()))
|
||||||
{
|
{
|
||||||
// TODO: Ged rid of this monster below...
|
// TODO: Ged rid of this monster below...
|
||||||
if (databaseSchemaSupport)
|
if (databaseSchemaSupport)
|
||||||
@@ -999,7 +991,7 @@ namespace DynamORM
|
|||||||
col.HasValue ? col.Value.IsKey : false).Value,
|
col.HasValue ? col.Value.IsKey : false).Value,
|
||||||
Type = DynamicExtensions.CoalesceNullable<DbType>(
|
Type = DynamicExtensions.CoalesceNullable<DbType>(
|
||||||
v.Value.Column != null ? v.Value.Column.Type : null,
|
v.Value.Column != null ? v.Value.Column.Type : null,
|
||||||
col.HasValue ? col.Value.Type : DbType.String).Value,
|
col.HasValue ? col.Value.Type : DynamicExtensions.TypeMap.TryGetNullable(v.Value.Type) ?? DbType.String).Value,
|
||||||
IsUnique = DynamicExtensions.CoalesceNullable<bool>(
|
IsUnique = DynamicExtensions.CoalesceNullable<bool>(
|
||||||
v.Value.Column != null ? v.Value.Column.IsUnique : null,
|
v.Value.Column != null ? v.Value.Column.IsUnique : null,
|
||||||
col.HasValue ? col.Value.IsUnique : false).Value,
|
col.HasValue ? col.Value.IsUnique : false).Value,
|
||||||
@@ -1026,7 +1018,7 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
Name = DynamicExtensions.Coalesce<string>(v.Value.Column == null || string.IsNullOrEmpty(v.Value.Column.Name) ? null : v.Value.Column.Name, v.Value.Name),
|
Name = DynamicExtensions.Coalesce<string>(v.Value.Column == null || string.IsNullOrEmpty(v.Value.Column.Name) ? null : v.Value.Column.Name, v.Value.Name),
|
||||||
IsKey = DynamicExtensions.CoalesceNullable<bool>(v.Value.Column != null ? v.Value.Column.IsKey : false, false).Value,
|
IsKey = DynamicExtensions.CoalesceNullable<bool>(v.Value.Column != null ? v.Value.Column.IsKey : false, false).Value,
|
||||||
Type = DynamicExtensions.CoalesceNullable<DbType>(v.Value.Column != null ? v.Value.Column.Type : null, DbType.String).Value,
|
Type = DynamicExtensions.CoalesceNullable<DbType>(v.Value.Column != null ? v.Value.Column.Type : null, DynamicExtensions.TypeMap.TryGetNullable(v.Value.Type)).Value,
|
||||||
IsUnique = DynamicExtensions.CoalesceNullable<bool>(v.Value.Column != null ? v.Value.Column.IsUnique : null, false).Value,
|
IsUnique = DynamicExtensions.CoalesceNullable<bool>(v.Value.Column != null ? v.Value.Column.IsUnique : null, false).Value,
|
||||||
Size = DynamicExtensions.CoalesceNullable<int>(v.Value.Column != null ? v.Value.Column.Size : null, 0).Value,
|
Size = DynamicExtensions.CoalesceNullable<int>(v.Value.Column != null ? v.Value.Column.Size : null, 0).Value,
|
||||||
Precision = DynamicExtensions.CoalesceNullable<byte>(v.Value.Column != null ? v.Value.Column.Precision : null, 0).Value,
|
Precision = DynamicExtensions.CoalesceNullable<byte>(v.Value.Column != null ? v.Value.Column.Precision : null, 0).Value,
|
||||||
|
|||||||
@@ -680,7 +680,8 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < args.Length; i++)
|
for (int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
var name = info.ArgumentNames[i].ToLower();
|
var fullName = info.ArgumentNames[i];
|
||||||
|
var name = fullName.ToLower();
|
||||||
|
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
@@ -701,7 +702,7 @@ namespace DynamORM
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
builder.Insert(name, args[i]);
|
builder.Insert(fullName, args[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -726,7 +727,8 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < args.Length; i++)
|
for (int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
var name = info.ArgumentNames[i].ToLower();
|
var fullName = info.ArgumentNames[i];
|
||||||
|
var name = fullName.ToLower();
|
||||||
|
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
@@ -755,7 +757,7 @@ namespace DynamORM
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
builder.Update(name, args[i]);
|
builder.Update(fullName, args[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -780,7 +782,8 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < args.Length; i++)
|
for (int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
var name = info.ArgumentNames[i].ToLower();
|
var fullName = info.ArgumentNames[i];
|
||||||
|
var name = fullName.ToLower();
|
||||||
|
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
@@ -805,7 +808,7 @@ namespace DynamORM
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
builder.Where(name, args[i]);
|
builder.Where(fullName, args[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -831,7 +834,8 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < args.Length; i++)
|
for (int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
var name = info.ArgumentNames[i].ToLower();
|
var fullName = info.ArgumentNames[i];
|
||||||
|
var name = fullName.ToLower();
|
||||||
|
|
||||||
// TODO: Make this nicer
|
// TODO: Make this nicer
|
||||||
switch (name)
|
switch (name)
|
||||||
@@ -906,7 +910,7 @@ namespace DynamORM
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
builder.Where(name, args[i]);
|
builder.Where(fullName, args[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,20 @@ namespace DynamORM.Mapper
|
|||||||
/// <remarks>Used when overriding schema.</remarks>
|
/// <remarks>Used when overriding schema.</remarks>
|
||||||
public byte? Scale { get; set; }
|
public byte? Scale { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Gets or sets a value indicating whether this kolumn is no allowed to be inserted.</summary>
|
||||||
|
/// <remarks>This is only a suggesstion to automated mapping.</remarks>
|
||||||
|
public bool IsNoInsert { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Gets or sets a value indicating whether this kolumn is no allowed to be updated.</summary>
|
||||||
|
/// <remarks>This is only a suggesstion to automated mapping.</remarks>
|
||||||
|
public bool IsNoUpdate { get; set; }
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
||||||
public ColumnAttribute() { }
|
public ColumnAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
||||||
/// <param name="name">Name of column.</param>
|
/// <param name="name">Name of column.</param>
|
||||||
@@ -73,6 +83,13 @@ namespace DynamORM.Mapper
|
|||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
||||||
|
/// <param name="isKey">Set column as a key column.</param>
|
||||||
|
public ColumnAttribute(bool isKey)
|
||||||
|
{
|
||||||
|
IsKey = isKey;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
||||||
/// <param name="name">Name of column.</param>
|
/// <param name="name">Name of column.</param>
|
||||||
/// <param name="isKey">Set column as a key column.</param>
|
/// <param name="isKey">Set column as a key column.</param>
|
||||||
@@ -82,6 +99,15 @@ namespace DynamORM.Mapper
|
|||||||
IsKey = isKey;
|
IsKey = isKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
||||||
|
/// <param name="isKey">Set column as a key column.</param>
|
||||||
|
/// <param name="type">Set column type.</param>
|
||||||
|
public ColumnAttribute(bool isKey, DbType type)
|
||||||
|
: this(isKey)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="ColumnAttribute" /> class.</summary>
|
||||||
/// <param name="name">Name of column.</param>
|
/// <param name="name">Name of column.</param>
|
||||||
/// <param name="isKey">Set column as a key column.</param>
|
/// <param name="isKey">Set column as a key column.</param>
|
||||||
|
|||||||
56
Tester/Program.cs
Normal file
56
Tester/Program.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using DynamORM;
|
||||||
|
using DynamORM.Mapper;
|
||||||
|
|
||||||
|
namespace Tester
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
[Table(Name = "dist_Distances")]
|
||||||
|
public class Distance
|
||||||
|
{
|
||||||
|
[Column(IsKey = true)]
|
||||||
|
public Guid StartAddress_Id { get; set; }
|
||||||
|
|
||||||
|
[Column(IsKey = true)]
|
||||||
|
public Guid EndAddress_Id { get; set; }
|
||||||
|
|
||||||
|
[Column(IsKey = true)]
|
||||||
|
public int VehicleType { get; set; }
|
||||||
|
|
||||||
|
[Column]
|
||||||
|
public int PostcodeDistanceInSecs { get; set; }
|
||||||
|
|
||||||
|
[Column]
|
||||||
|
public decimal PostcodeDistanceInKms { get; set; }
|
||||||
|
|
||||||
|
[Column]
|
||||||
|
public int IsDepotDistance { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Main(string[] args)
|
||||||
|
{
|
||||||
|
string conns = string.Format("Server={0};Port={1};Userid={2};Password={3};Database={4};Protocol=3;SSL=false;Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=15;",
|
||||||
|
"192.168.1.6", 5432, "ted", "ted123", "TED_Altom");
|
||||||
|
|
||||||
|
using (var db = new DynamicDatabase(Npgsql.NpgsqlFactory.Instance, conns, DynamORM.DynamicDatabaseOptions.SupportSchema | DynamORM.DynamicDatabaseOptions.SupportLimitOffset))
|
||||||
|
{
|
||||||
|
var s = db.GetSchema<Distance>();
|
||||||
|
Console.Out.WriteLine(s.Count);
|
||||||
|
|
||||||
|
DynamicTypeMap mapper = DynamORM.Mapper.DynamicMapperCache.GetMapper<Distance>();
|
||||||
|
using (var con = db.Open())
|
||||||
|
using (var cmd = con.CreateCommand())
|
||||||
|
{
|
||||||
|
Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters = new Dictionary<IDbDataParameter, DynamicPropertyInvoker>();
|
||||||
|
|
||||||
|
db.Insert<Distance>(new Distance[] { });
|
||||||
|
|
||||||
|
//db.PrepareBatchInsert<Distance>(mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Tester/Properties/AssemblyInfo.cs
Normal file
36
Tester/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("Tester")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("Tester")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("dbff9475-06f5-400e-bc17-57c14d9d9cb9")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
66
Tester/Tester.csproj
Normal file
66
Tester/Tester.csproj
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
|
<ProductVersion>8.0.30703</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{F747AA57-BEA7-4FB8-B371-546296789AEF}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Tester</RootNamespace>
|
||||||
|
<AssemblyName>Tester</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Npgsql">
|
||||||
|
<HintPath>..\..\..\..\..\Development\Source\TED\Demo\Libraries\Npgsql.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DynamORM\DynamORM.csproj">
|
||||||
|
<Project>{63963ED7-9C78-4672-A4D4-339B6E825503}</Project>
|
||||||
|
<Name>DynamORM</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user