2016-12-10 21 views
3

한 줄의 코드를 작성한 지 오래되었으므로 잠시만 기다려주세요.C# : 'IEnumerable <Student>'에 'Interters'에 대한 정의가 없습니다.

IntelliSense에서 Names 뒤에 Intersect 메서드가 표시 되더라도 두 개의 IEnumerable을 비교할 때 다음 오류가 발생합니다.

데이터베이스 쿼리 결과와 html의 정렬 된 목록을 비교하려고합니다. '교차'에 대한 정의 및 최고의 확장 메서드 오버로드 'Queryable.Intersect (된 IQueryable, 는 IEnumerable을)'가 포함되어 있지 않습니다

'는 IEnumerable'유형 '된 IQueryable'

의 수신기가 필요
namespace Data.Repositories 
{ 
    public class StudentsRepository 
    { 
     public class Student 
     { 
      public string FullName { get; set; } 
     } 

     public static IEnumerable<Student> GetData(string CardNumber, string Section) 
     { 
      // FullName varchar(300) in Database 
      return CommonFunctions.ExecuteReader1<Student>(QryStudentSectionDetails(CardNumber, Section)).AsQueryable(); 
     } 
    } 
} 


namespace Tests.ActionsLibrary.StudentPaper 
{ 
    public class StudentActions:TestBase 
    { 
     bool IsMatch = false; 

     // Get Names from DataBase 
     IEnumerable<Student> Names = GetData(CardNumber, Section); 

     // Get Names from Ordered list in HTML 
     IEnumerable<IWebElement> OrderedList = driver.FindElements(By.XPath("//li[@ng-repeat='Names']")); 

     if (Names.Count() == OrderedList.Count() && Names.Intersect(OrderedList).Count() == OrderedList.Count()) // The error is shown here. 
     { IsMatch = true; } 

내가 뭘 잘못하고 있는지 궁금해. 어떤 도움이라도 대단히 감사하겠습니다. 감사.

는 끝에서 코드는 다음과 같습니다

IEnumerable<string> Names = GetData(CardNumber, Section).Select(s => s.FullName); 
    IEnumerable<string> OrderedList = driver.FindElements(By.XPath("//li[@ng-repeat='Names']")).Select(i => i.Text); 

당신의 도움을 대단히 감사합니다.

+0

'Students'와'IWebElements'가 어떻게 교차 할 것이라고 생각합니까? 그 위에 다른 문제가있을 수도 있지만, 실제로는 처리해야 할 문제입니다. – SimpleVar

답변

4

Intersect은 두 컬렉션이 같은 유형이어야하기 때문입니다. 컬렉션 또는 Student 컬렉션과 IWebElement 컬렉션으로 전화하려고합니다.

Intersect을 호출하기 전에 동일한 유형의 콜렉션이 두 개 있는지 확인하거나 다른 방법으로 작업을 수행하십시오.

당신은 쉽게 비교 될 수있는 일에 프로젝트를 모두 수집 (예 : IEnumerable<string>) 중 하나

var studentNames = Names.Select(student => student.Name); 
var webElementNames = OrderedList.Select(webElement => webElement.Name); 

또는 당신은 아마 그렇게 할 All을 사용할 수

if(Names.All(student => OrderedList.Any(webElement => webElement.Name == student.Name))) 

그렇게하지 어떤 특성을 비교할 것인지를 알고 있으므로, 술어를 의미있는 것으로 대체하십시오.

+0

매력처럼 작동했습니다. 고맙습니다! – frankztein