I have the following two classes auto generated with Entity Framework using database first;
public partial class UserXml
{
public UserXml()
{
this.UserXmlHotel = new HashSet<UserXmlHotel>();
}
public long UserId { get; set; }
public string Password { get; set; }
public bool Enabled { get; set; }
public byte FailedAttempt { get; set; }
public virtual User User { get; set; }
public virtual UserXmlIp UserXmlIp { get; set; }
public virtual ICollection<UserXmlHotel> UserXmlHotel { get; set; }
}
and
public partial class UserCustomer
{
public UserCustomer ()
{
this.UserCustomerHotel = new HashSet<UserCustomerHotel >();
}
public long UserId { get; set; }
public bool Enabled { get; set; }
public string Password { get; set; }
}
I've then created the following classes;
public partial class UserXml : IUser
{
}
public partial class UserCustomer : IUser
{
}
public static class EntityExtensions
{
public static IQueryable<T> Enabled<T>(this IQueryable<T> source) where T : IUser
{
return source.Where(x => x.Enabled);
}
}
I have a interface as;
public interface IUser
{
bool Enabled { get; }
}
Want I'm wanting to do is combine the same call for each entity using the same re-usable code; So take
using(var Context = new EscapeEntities())
{
bool bEnabled = Context.UserXml.First(u => u.UserId == iUserId).Enabled;
}
and
using(var Context = new EscapeEntities())
{
bool bEnabled = Context.UserCustomer.First(u => u.UserId == iUserId).Enabled;
}
I'm wanting to use my EntityExtensions class, but I'm having trouble getting it to work. Any pointers ?