List<Contacts>
data = db.ContactData.TakeWhile( ( m, UserId ) => m.FId == UserId ).ToList<Contacts>();
When I run the site, I get this error:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[My_MSI.Net.Models.Entities.Contacts] TakeWhile[Contacts](System.Linq.IQueryable`1[My_MSI.Net.Models.Entities.Contacts], System.Linq.Expressions.Expression`1[System.Func`3[My_MSI.Net.Models.Entities.Contacts,System.Int32,System.Boolean]])'
method, and this method cannot be translated into a store expression.
When I checked bing.com for how to use TakeWhile, I found this example:
eric2820
Contributor
2777 Points
1161 Posts
TakeWhile sytax question...
Jan 09, 2013 07:53 PM|LINK
What is wrong with this statment:
List<Contacts> data = db.ContactData.TakeWhile( ( m, UserId ) => m.FId == UserId ).ToList<Contacts>();
When I run the site, I get this error:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[My_MSI.Net.Models.Entities.Contacts] TakeWhile[Contacts](System.Linq.IQueryable`1[My_MSI.Net.Models.Entities.Contacts], System.Linq.Expressions.Expression`1[System.Func`3[My_MSI.Net.Models.Entities.Contacts,System.Int32,System.Boolean]])' method, and this method cannot be translated into a store expression.
When I checked bing.com for how to use TakeWhile, I found this example:
IEnumerable<string> query = fruits.AsQueryable().TakeWhile((fruit, index) => fruit.Length >= index);
UserId is a property in the Controller so this should be legal right?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
DarrellNorto...
All-Star
86809 Points
9646 Posts
Moderator
MVP
Re: TakeWhile sytax question...
Jan 10, 2013 01:36 AM|LINK
LINQ to Entities provides LINQ operators to access a database using Entity Framework. Not all operators are supported. TakeWhile is not supported.
You can see the full list of supported and not supported LINQ operators here:
http://msdn.microsoft.com/en-us/library/vstudio/bb738550(v=vs.110).aspx
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: TakeWhile sytax question...
Jan 11, 2013 09:32 AM|LINK
Hi,
You can use AsEnumerable() method to convert from LINQ-TO-EF to LINQ-TO-OBJECT and have a try like this following:
List<Contacts> data = db.ContactData.AsEnumerable().TakeWhile( ( m, UserId ) => m.FId == UserId ).ToList();