I am working on this mvc project following Rob Connery's storefront video series and applying the techniques. On the filtering and extensions methods, i started repeating myself a lot such as:
public static Sponsor WithID(this IQueryable<Sponsor>qry, int ID)
{
return qry.SingleOrDefault(s => s.ID== ID);
}
public static Keyword WithID(this IQueryable<Keyword>qry,int ID)
{
return qry.SingleOrDefault(s => s.ID== ID);
}
....
To prevent this,I try to write a generic extension like this:
public static T WithID<T>(this IQueryable<T>qry,int ID)
{
return qry.SingleOrDefault(s=>ID==ID);
}
however s does not have ID, so how would you solve this?