1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
public static T Get<T>(string command, List<AdapterParameter> parameters = null, params Type[] args)
{
DBObjectWrapping mapping = WrapObject<T>();
T entity = default(T);
IEnumerable<DbDataReader> results = OleDbDataAdapter.ExecuteQuery(command, parameters);
foreach (DbDataReader line in results)
{
entity = (T)Activator.CreateInstance<T>();
foreach (DBFieldMapping map in mapping.Mappings.Where(x => x.IsCollection == false))
map.PropertyInformation.SetValue(entity, WrapValue(map.PropertyInformation.PropertyType, line.GetValue(line.GetOrdinal(map.DBFieldName))));
break;
}
if (args != null)
{
foreach (Type typ in args)
{
DBFieldMapping map = null;
if ((map = mapping.Mappings.Where(x => x.IsCollection && x.TypeCollection == typ).FirstOrDefault()) != null)
map.PropertyInformation.SetValue(entity, FetchList<typ.GetType()>(results));
}
}
return entity;
} |
Partager