My goal is to use entity frameworks (perhaps reflection), to create functions like this:
public List<MyRows> getTableByName(string tableName)
{
ObjectQuery objectQuery = (ObjectQuery)getObjectSet(tableName, m_context); // How do you do this part???
List<MyRows> rows = new List<MyRows>();
SortByColumn(objectQuery); // I can do this myself.
MyWhereClauses(objectQuery); // I can do this myself.
rows = ConvertToMyRows(objectQuery.ToList()); // I can do this myself.
}
The class "MyRows" is invented by me so I can add more properties. The "ConvertToMyRows", "MyWhereClauses", and "getObjectset" are also made-up functions.
Is this sort of thing possible in Entity Framework?
How do you do a sort of "getObjectSet" type function based on Template T or string of the table name?
I'm tired of writing Data Access files that have specific functions just to generate a list of items.
SOLVED:
public IQueryable<T> GetTable<T>() where T : class
{
var table = m_entities.CreateObjectSet<T>();
return table;
}
public string MyData<T>() where T: class { var table = GetTable<T>(); //order here }
public IQueryable<T> GetTable<T>() where T : class
{
var table = m_entities.CreateObjectSet<T>();
return table;
}
public string MyData<T>() where T: class {
var table = GetTable<T>(); //order here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With