ConvertToTable(from Poco class to Table)
来源:互联网 发布:ubuntu服务器密码修改 编辑:程序博客网 时间:2024/06/17 07:31
protected DataTable ConvertToDataTable(IList<T> list)
{
DataTable table = new DataTable();
int indexOfGeoColumn = -1;
List<DataColumn> primaryKeys = new List<DataColumn>();
for (int i = 0; i < _columns.Count(); i++)
{
var col = _columns[i];
Type propType = col.PropertyType;
DataColumn column = new DataColumn();
column.ColumnName = col.Name;
if (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Nullable<>))
column.DataType = Nullable.GetUnderlyingType(propType);
else
column.DataType = propType;
RequiredAttribute required = (RequiredAttribute)Attribute.GetCustomAttribute(propType, typeof(RequiredAttribute));
if (required != null)
column.AllowDBNull = false;
//special case that we need to consider
if (propType.Equals(typeof(DbGeography)))
{
column.DataType = typeof(SqlGeography);
indexOfGeoColumn = i;
}
if (_keyNames.Contains(col.Name))
primaryKeys.Add(column);
table.Columns.Add(column);
}
table.PrimaryKey = primaryKeys.ToArray();
object[] values = new object[_columns.Length];
for (int j = 0; j < list.Count; j++)
{
for (int i = 0; i < values.Length; i++)
{
if (indexOfGeoColumn == i)
{
var dbGeo = (DbGeography)_columns[i].GetValue(list[j]);
if (dbGeo == null)
{
values[i] = null;
}
else
{
SqlGeography sqlGeo2 = SqlGeography.STGeomFromWKB(new SqlBytes(dbGeo.AsBinary()), dbGeo.CoordinateSystemId);
values[i] = sqlGeo2;
}
}
else
{
values[i] = _columns[i].GetValue(list[j]);
}
}
table.Rows.Add(values);
}
return table;
}
{
DataTable table = new DataTable();
int indexOfGeoColumn = -1;
List<DataColumn> primaryKeys = new List<DataColumn>();
for (int i = 0; i < _columns.Count(); i++)
{
var col = _columns[i];
Type propType = col.PropertyType;
DataColumn column = new DataColumn();
column.ColumnName = col.Name;
if (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Nullable<>))
column.DataType = Nullable.GetUnderlyingType(propType);
else
column.DataType = propType;
RequiredAttribute required = (RequiredAttribute)Attribute.GetCustomAttribute(propType, typeof(RequiredAttribute));
if (required != null)
column.AllowDBNull = false;
//special case that we need to consider
if (propType.Equals(typeof(DbGeography)))
{
column.DataType = typeof(SqlGeography);
indexOfGeoColumn = i;
}
if (_keyNames.Contains(col.Name))
primaryKeys.Add(column);
table.Columns.Add(column);
}
table.PrimaryKey = primaryKeys.ToArray();
object[] values = new object[_columns.Length];
for (int j = 0; j < list.Count; j++)
{
for (int i = 0; i < values.Length; i++)
{
if (indexOfGeoColumn == i)
{
var dbGeo = (DbGeography)_columns[i].GetValue(list[j]);
if (dbGeo == null)
{
values[i] = null;
}
else
{
SqlGeography sqlGeo2 = SqlGeography.STGeomFromWKB(new SqlBytes(dbGeo.AsBinary()), dbGeo.CoordinateSystemId);
values[i] = sqlGeo2;
}
}
else
{
values[i] = _columns[i].GetValue(list[j]);
}
}
table.Rows.Add(values);
}
return table;
}
0 0
- ConvertToTable(from Poco class to Table)
- An association from the table * refers to an unmapped class: *
- An association from the table refers to an unmapped class
- An association from the table * refers to an unmapped class: *
- An association from the table refers to an unmapped class
- org.hibernate.MappingException: An association from the table tuser refers to an unmapped class: Role
- 映射异常: An association from the table tb_baoxiao refers to an unmapped class: int
- An association from the table work_output refers to an unmapped class: org.ejs.sys.model.Part
- 关于An association from the table refers to an unmapped class
- An association from the table PersonAddress refers to an unmapped class
- 映射异常: An association from the table TBL_TRAIN_COURSE_MONTH_PLAN refers to an unmapped class
- An association from the table suppliersuserinfo refers to an unmapped class
- 2.An association from the table refers to an unmapped class:错误
- hibernate错误:An association from the table ....... refers to an unmapped class
- An association from the table student refers to an unmapped class: com.test.model.Team
- An association from the table User refers to an unmapped class
- Hibernate:关于An association from the table refers to an unmapped class
- org.hibernate.MappingException: An association from the table STREET refers to an unmapped class: e
- VB.NET的拖放操作
- 继承,特质
- Nginx+PHP+Swfupload 上传大文件
- centos 7下安装配置nginx
- xUtils 中 HttpUtils 的使用
- ConvertToTable(from Poco class to Table)
- 2015 Multi-University Training Contest 3 || HDU 5325 Crazy Bobo || 类似bfs
- Dwr 前端报Error提示解决办法
- 小白学开发(iOS)OC_构造方法(2015-07-29)
- android TextView自动实现省略号
- 防黑指南:普通用户上网时该注意什么?
- HDU5319
- MVVM指南二:Flickr搜索深入
- 程序员永远的痛之字符编码的奥秘