/// <summary> /// 把指定的实体列表中的数据完全转换到一个 DataTable 中。 /// </summary> /// <param name="list"></param> /// <returns></returns> public static DataTable ToDataTable(this EntityList list) { DataTable table = new DataTable(); //找到属性容器 var container = list.GetRepository().EntityMeta.ManagedProperties; var properties = container.GetCompiledProperties(); foreach (var property in properties) { //table.Columns.Add(property.Name, property.PropertyType); table.Columns.Add(property.Name, TypeHelper.IgnoreNullable(property.PropertyType)); } list.EachNode(item => { var row = table.NewRow(); for (int j = 0, c2 = properties.Count; j < c2; j++) { var property = properties[j]; var value = item.GetProperty(property); row[j] = value ?? DBNull.Value; } table.Rows.Add(row); return(false); }); return(table); }
/// <summary> /// 保存某个实体列表。 /// </summary> /// <param name="entityList">The entity list.</param> public static void Save(EntityList entityList) { entityList.GetRepository().Save(entityList); }
private static Entity FindOrCreate(EntityList list, JObject jEntity) { var id = TryGetId(jEntity); Entity child = null; if (id != null) { child = list.Find(id, true); } if (child == null) { child = list.GetRepository().New(); list.Add(child); } return child; }