0

当我尝试代码时

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;

我收到“找不到查询模式的实现..找不到选择”。

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

4

2 回答 2

1

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

你的意思是from actr in act select actr

于 2009-10-19T09:41:17.407 回答
1

您不能直接在Actor类上进行选择,因为它没有实现IEnumerable也不IQueryable。您应该改为查询act数组。

于 2009-10-19T09:44:01.283 回答