0

I have table StudentAccount with columns Code,Amount,Description,Valid Period for selected period there might be same code and description write a linq query that gets the data Code/Description needs to be unique for the selected date range.( the date is in the format 1/1/1990-1/1/1991)

    public IEnumerable<StudentAccount> StudentAccountdata
    {
        get { return Context.StudentAccount.Where(q=>q.Active).OrderBy(q =>q.Description).ToList(); }            
    }
1
  • 2
    how can u say like this..if u can answer it fine..dont make silly comments..problem can be small or big Commented Feb 25, 2012 at 3:50

1 Answer 1

1

Use IEqualityComparer like so:

public class StdComparer : IEqualityComparer<StudentAccount>
{
    #region IEqualityComparer<StudentAccount> Members

    public bool Equals(StudentAccount x, StudentAccount y)
    {
        return x.Code == y.Code && x.Description == y.Description;
    }

    public int GetHashCode(StudentAccount obj)
    {
        return 0;
    }

    #endregion
}

Then

public IEnumerable<StudentAccount> StudentAccountdata
{
    get { return Context.StudentAccount.Where(q=>q.Active && 
                    q.Date >= BeginDate && 
                    q.Date <= EndDate)
                   .OrderBy(q =>q.Description).Distinct(new StdComparer()); }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.