PC Review


Reply
Thread Tools Rate Thread

Contains Error

 
 
shapper
Guest
Posts: n/a
 
      6th May 2009
Hello,

I have the following Query:

public IQueryable<Tag> GetTags(IList<Tag> tags) {
IQueryable<Tag> _tags = (from t in context.aspnet_Tags
join tn in tags on t.Name equals
tn.Name
select new Tag {
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.

I am not sure what I am doing wrong ...

Any idea?

Thank You,
Miguel


 
Reply With Quote
 
 
 
 
Pavel Minaev
Guest
Posts: n/a
 
      6th May 2009
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.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server Error: 451, Socket Error: 10053, Error Number: 0x800CCC0F =?Utf-8?B?RGFuaWVsYQ==?= Windows XP Help 3 17th Aug 2007 05:10 PM
Access error 3197 and JETCOMP.exe error "Error compacting database =?Utf-8?B?Vmlja3k=?= Microsoft Access 2 21st Jul 2007 12:29 AM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 Microsoft ASP .NET 2 27th Mar 2006 09:43 PM
3 Problems - Media Center Error, Date/Time Error, Downloading Updates Error angieangie Windows XP General 0 23rd Dec 2005 06:33 PM
A runtime error has occured. Do you want to debug? Line: 1 Error: syntax error Eric Windows XP Networking 0 24th Nov 2003 03:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:12 PM.