I have a lot of classes
public class City
{
public int CityID { get; set; }
public string Name { get; set; }
public string Comment { get; set; }
public virtual ICollection<ApplicationUser> DryCleanings { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateChanged { get; set; }
public bool IsDeleted { get; set; }
}
public class Marker
{
public int MarkerID { get; set; }
public string Name { get; set; }
public string Comment { get; set; }
public byte[] Icon { get; set; }
public virtual IEnumerable<ApplicationUser> Cleanings { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateChanged { get; set; }
public bool IsDeleted { get; set; }
}
.
.
.
They all have the same three properties
public DateTime DateCreated { get; set; }
public DateTime DateChanged { get; set; }
public bool IsDeleted { get; set; }
I need to write same where query for each of them, something like this
_db.Cities.Where(c => !c.IsDeleted && c.DateChanged > oldDate && c.DateChanged < oldDate);
_db.Markers.Where(m => !m.IsDeleted && m.DateChanged > oldDate && m.DateChanged < oldDate);
i do not want write this query for every class. Can i write this predicate once and use for all?
ps. I tried inherited from Interface
public interface IDate
{
public DateTime DateCreated { get; set; }
public DateTime DateChanged { get; set; }
public bool IsDeleted { get; set; }
}
and write something like this
Expression<Func<IDate, bool>> lessOldDate = c => !c.IsDeleted && c.DateChanged > oldDate && c.DateChanged < oldDate;
but i getting type IDate however i need Marker