views:

252

answers:

1

This fails with an error with the method "Contains" is not supported.

List<int> usedID= new List<int> { 1, 2, 3 };
var f = WebPageContent.Find(x => !usedID.Contains(x.PageID));

Seems odd so what's the alternative approach?

This doesn't work either:

var dd = from i in WebPageContent.All() 
         where !usedID.Contains(i.PageID) 
         select i;

This does but is it the recommended approach:

var table = new WebPageContentTable(_db.DataProvider);
var g = new SubSonic.Query.Select()
            .From(table)
            .Where(table.ID)
            .In(usedID)
            .Execute();
+2  A: 

Not knowing anything about Subsonic/Subsonic 3 I suggest that you use the Any (or Contains) extension method and see if it's supported.

List<int> usedID= new List<int> { 1, 2, 3 };
var f = WebPageContent.Find(x => !usedID.Any( e => e == x.PageID));
bruno conde
You da man, thanks!
Jon
If usedId is empty the Find falls over because of a null.protected virtual Expression VisitUnary(UnaryExpression u) { Expression operand = this.Visit(u.Operand); //********** operand IS NULL HERE ******** if (operand != u.Operand) { return Expression.MakeUnary(u.NodeType, operand, u.Type, u.Method); } return u; }
Jon
I also ran into this problem, and the answer above does work, but I believe that it is a problem with the SubSonic SQL translator, and not an error in your LINQ syntax. Even Rob Conery, the writer of SubSonic says it should work. See this reference: http://blog.wekeroad.com/blog/creating-in-queries-with-linq-to-sql/
Steve