Skip to content

Instantly share code, notes, and snippets.

@alexsandro-xpt
Created February 26, 2014 14:33
Show Gist options
  • Save alexsandro-xpt/9230438 to your computer and use it in GitHub Desktop.
Save alexsandro-xpt/9230438 to your computer and use it in GitHub Desktop.
Mapping database to entity
public override IQueryable<TEntity> GetAll()
{
var table = base.Context.ExecutarSQL(Querys[QueryType.GetAll], null);
var i = table.Rows.Cast<object>().Select(row =>
{
var entity = new TEntity();
foreach (var prop in entity.GetType().GetProperties())
{
var property = entity.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance);
if (null != property && property.CanWrite)
{
property.SetValue(entity, ((DataRow)row)[prop.Name], null);
}
}
return entity;
});
return i.AsQueryable();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment