c# - How to get List of results from list of ID values with LINQ to SQL? -
i have list of id values:
list<int> myids { get; set; }
i'd pass list interface repository , have return list match id values pass in.
list<mytype> mytypes = new list<mytype>(); imyrepository myrepos = new sqlmyrepository(); mytypes = myrepos.getmytypes(this.myids);
currently, getmytypes() behaves this:
public mytype getmytypes(int id) { return (from mytype in db.mytypes mytype.id == id select new mytype { myvalue = mytype.myvalue }).firstordefault(); }
where iterate through myids , pass each id in , add each result list.
how need change linq can pass in full list of myids , list of mytypes out? getmytypes() have signature similar to
public list<mytype> getmytypes(list<int> myids)
public list<mytype> getmytypes(list<int> ids) { return (from mytype in db.mytypes ids.contains(mytype.id) select new mytype { myvalue = mytype.myvalue }).tolist(); }
Comments
Post a Comment