Query Distinct is not working. Any idea?

Apr 18, 2014 at 12:52 PM
I have the following custom Repository using Distinct and the distinct is not working.
public static class MemberRepository
    {
     


        public static IEnumerable<AutoComplete> GetDistinctMembers(
             this IRepository<Member> memberRepository,
             string text)
        {
            var result = memberRepository.Query(x => x.LastName.StartsWith(text)).Select(l=>new AutoComplete
            {
              LastName  = l.LastName

            }).Distinct();

            return result;
        }
    }
Below you'll find my test.
[TestMethod]
        public void SearchMember()
        {
            IRepositoryAsync<Member> _memberRepository;
            IUnitOfWorkAsync _unitOfWorkAsync; 
           
            using (IDataContextAsync MyFakeContext = new MyFakeContext ())

            {
                _memberRepository = new Repository<Member>(MyFakeContext );
               _unitOfWorkAsync = new UnitOfWork(MyFakeContext );

               _memberRepository.Insert(new Member { Id= 1, LastName = "Doug", ObjectState = ObjectState.Added });
               _memberRepository.Insert(new Member { Id= 2, LastName = "Doug", ObjectState = ObjectState.Added });
               _memberRepository.Insert(new Member { Id= 3, LastName = "Doug", ObjectState = ObjectState.Added });

               _unitOfWorkAsync.SaveChangesAsync();
               Assert.AreEqual(3, _memberRepository.Query(x=>x.LastName=="Doug").Select().Count());
               var member = _memberRepository.GetDistinctMembers("Dou");
               Assert.IsNotNull(member);
               Assert.AreEqual(1, member.Count());
            }
        }
The last Assert is 3
Coordinator
Apr 22, 2014 at 9:58 PM
Implement Distinct with memberRepository.Querayble(), which will return IQueryable.
Marked as answer by lelong37 on 4/22/2014 at 1:58 PM
Apr 23, 2014 at 2:47 AM
Thanks for guide me on the right direction IQueryable<TEntity> ODataQueryable() did the work. Sample code below.
    public static class OrderRepository
    {
        public static IEnumerable<string> GetDistinctCustomer(
            this IRepository<Order> orderRepository)
        {
            var result=orderRepository
                .ODataQueryable()
                .Select(x =>  x.CustomerID 
                ).Distinct();
            return result;
    }
}
SQL
SELECT 
    [Distinct1].[CustomerID] AS [CustomerID]
    FROM ( SELECT DISTINCT 
        [Extent1].[CustomerID] AS [CustomerID]
        FROM [dbo].[Orders] AS [Extent1]
    )  AS [Distinct1]