On May 6, 2:19*pm, shapper <mdmo...@gmail.com> wrote:
> Hello,
>
> I have the following Query:
>
> * * public IQueryable<Tag> GetTags(IList<Tag> tags) {
> * * * IQueryable<Tag> _tags = (from t in context.aspnet_Tags
> * * * * * * * * * * * * * * * *join tn intags on t.Name equals
> tn.Name
> * * * * * * * * * * * * * * * *select newTag {
> * * * * * * * * * * * * * * * * *Id =t.TagId,
> * * * * * * * * * * * * * * * * *Created = t.Created,
> * * * * * * * * * * * * * * * * *Name = t.Name,
> * * * * * * * * * * * * * * * * *Updated = t.Updated
> * * * * * * * * * * * * * * * *}).AsQueryable();
> * * * return _tags;
>
> * * } // GetTags
>
> Basically I receive a list of Tags that contain only the names.
> Then I look into the database for tags having the same name.
> If exists I get the id, Created and Updated fields and return the
> tags.
>
> I am using this method in a few situations. One of them is to check if
> all tags inserted by the user exist in the database so I have:
>
> var AllFound = repository.GetTags(tags).Count() == tags.Count;
>
> This is not working an I get the following error:
> Local sequence cannot be used in LINQ to SQL implementation of query
> operators except the Contains() operator.
"tags" in code above is a List<T>, right? And in GetTags(), you're
trying to join it with a LINQ to SQL Table. It won't work - you cannot
mix collections like that. You can join two Tables (and then it will
generate an SQL JOIN), or you can join two Lists (or, in general,
IEnumerables), and then the join will be performed in-memory, but you
cannot mix.
If you _do_ want an in-memory join, use AsEnumerable() on your Table
so that LINQ to SQL provider doesn't kick in.
|