开发者

Select error in Linq

开发者 https://www.devze.com 2022-12-08 16:58 出处:网络
When i tried the code Actor[] act = new Actor[] { new Actor { Name = \"Jacky\", ID = \"JZ01\", FilmList = { new Film

When i tried the code

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 开发者_JAVA技巧Period
     {
         get { return period; }
         set { period = value; }
     }
   }

...Main() ..

var sqry = from actr in Actor select actr;

I recieved "Could not find the implementation of the query pattern..Select not found".

May i know the reason which stops the execution?


The Actor class doesn't implement IEnumerable or IQueryable, so you can't run a query on it (and anyway Actor is a type, not an instance of a type)...

Did you mean from actr in act select actr ?


You can't do a select directly over the Actor class since it does not implement IEnumerable nor IQueryable. You should instead query the act array.

0

精彩评论

暂无评论...
验证码 换一张
取 消