I need to add some “search queries” to my C # .NET application. In principle, there will be many tables where they all have the same schema but contain different values.
I came across writing the same code over and over (there must be an OO way for this ..)
[edit - modified below to show more complete information] In any case, I would like to:
public List<GenericLookupE> GetLookupItems( string what )
{
if ( "regions" == what ) return FetchLookup( db.lkRegions.AsQueryable() );
if ( "partners" == what ) return FetchLookup( db.lkPartners.AsQueryable() );
if ( "funders" == what ) return FetchLookup( db.lkFunders.AsQueryable() );
return null;
}
private List<GenericLookupE> FetchLookup<T>( IQueryable<T> lookup )
{
return lookup.OrderBy( p => p.Sequence ).Select
( p => new GenericLookupE()
{
ID = p.ID
,Label = p.Label
,StateCode = p.StateCode
,Sequence = p.Sequence
}
).ToList();
}
Of course, the problem is that the compiler does not know what p => p.Sequence is. Any ideas?
Thanks to everyone.
source
share