在Linq中选择错误

时间:2009-10-19 09:36:40

标签: c# compiler-errors

当我尝试代码时

Actor[] act =
new Actor[]
{
  new Actor
  {
    Name = "Jacky",
    ID = "JZ01",
    FilmList =
    {
      new Film
      {
        Title = "Twin Brothers",
        Period = Convert.ToDateTime("01/Nov/1993")
      },
      new Film
      {
        Title = "Police Story",
        Period = Convert.ToDateTime("05/Aug/1989")
      }
    }
  },
  new Actor
  {
    Name = "Tom Cruise",
    ID = "JZ09",
    FilmList = 
    {
      new Film
      {
        Title = "Mission Impossible I",
        Period = Convert.ToDateTime("01/Jun/1998")
      },
      new Film 
      {
        Title = "Mission Impossible II",
        Period = Convert.ToDateTime("05/Aug/2001")
      }
    }
  }  
};

class Actor
{
    string name;
    string id;
    List<Film> flm=new List<Film>();

     public string Name
     {
       get { return name; }
       set { name = value; }
     }

     public string ID
     {
          get { return id; }
          set { id = value; }
     }

     public List<Film> FilmList
     {
        get { return flm; }
        set { flm = value; }
     }

   }

  class Film
  {
     string title;
     DateTime period;

     public string Title
     {
       get { return title; }
       set { title = value; }
     }

     public DateTime Period
     {
         get { return period; }
         set { period = value; }
     }
   }

...主要() ..

var sqry = from actr in Actor select actr;

我收到了“无法找到查询模式的实现。选择未找到”。

我可以知道停止执行的原因吗?

2 个答案:

答案 0 :(得分:1)

Actor类未实现IEnumerableIQueryable,因此您无法对其进行查询(无论如何Actor是一种类型,而不是类型的实例)...

您的意思是from actr in act select actr吗?

答案 1 :(得分:1)

您无法直接在Actor课程上进行选择,因为它未实施IEnumerableIQueryable。您应该查询act数组。