2012-02-25 75 views
0

我有表StudentAccount的列代碼,數量,說明,對於週期選擇有可能是相同的代碼和說明 寫一個LINQ查詢獲取數據碼有效期 /說明需要是在所選日期範圍獨特(日期格式爲1/1/1990-1/1/1991)與LINQ查詢檢索數據

public IEnumerable<StudentAccount> StudentAccountdata 
    { 
     get { return Context.StudentAccount.Where(q=>q.Active).OrderBy(q =>q.Description).ToList(); }    
    } 
+2

你怎麼能這樣說,如果你可以回答它罰款..不要做出愚蠢的評論..問題可以是小的或大的 – GANI 2012-02-25 03:50:05

回答

1

使用IEqualityComparer像這樣:

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 
} 

的n

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()); } 
}