using System; using System.Runtime.Serialization; using ZeroLevel.Specification; namespace ZeroLevel.SqlServer { [DataContract] [Serializable] public class IdentitySpecification : BaseSpecification where T : IEntity { [DataMember] protected Guid _id; public IdentitySpecification(Guid id) { _id = id; } public override bool IsSatisfiedBy(T o) { return o.Id == _id; } public static ISpecification Create(Guid id) { return new IdentitySpecification(id); } public static ISpecification Create(IEntity entity) { return new IdentitySpecification(entity.Id); } } [DataContract] [Serializable] public class IdentitySpecification : BaseSpecification { [DataMember] private TKey _id; private readonly IDbMapper _mapper; public IdentitySpecification(TKey id, bool poco) { _id = id; _mapper = DbMapperFactory.Create(poco); } public override bool IsSatisfiedBy(T o) { return _mapper.Id(o).Equals(_id); } public static ISpecification Create(TKey id, bool poco) { return new IdentitySpecification(id, poco); } } }