471,348 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Linq 2 sql, enum, no supported translation to SQL

Hi, I'm using linq 2 sql, and I specified a custom enum type
(CompanyType) to one of the Company table field.
When I'm querying like this:

IEnumerable<CompanyTypevalidTypes= ...;
var v = from c in db.Companies
where validTypes.Contains(c.CompanyType)
select c;

I got an exception says:

Method 'Boolean Contains(MyNamespace.CompanyType)' has no
supported translation to SQL.

If I use int instead of "MyNamespace.CompanyType" as the type of
property "CompanyType" (and the IEnumerable<intvalidTypes),
everything works. So what should I do to make my custom enum types
work?

Thanks!
Jun 27 '08 #1
1 3904
On Jun 24, 12:23*pm, deerchao <deerc...@gmail.comwrote:
Hi, I'm using linq 2 sql, and I specified a custom enum type
(CompanyType) to one of the Company table field.
When I'm querying like this:

IEnumerable<CompanyTypevalidTypes= ...;
var v = from c in db.Companies
* * where validTypes.Contains(c.CompanyType)
* * select c;

I got an exception says:

* * Method 'Boolean Contains(MyNamespace.CompanyType)' has no
supported translation to SQL.

If I use int instead of "MyNamespace.CompanyType" as the type of
property "CompanyType" (and the IEnumerable<intvalidTypes),
everything works. So what should I do to make my custom enum types
work?

Thanks!
Sorry, it's my fault.
I checked again, the validTypes is not of Type
IEnumerable<CompanyTypebut HashSet<CompanyType>.
Everything works after I change the declared type of validTypes into
IEnumerable.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Rouben Rostamian | last post: by
12 posts views Thread by Charlie | last post: by
8 posts views Thread by Alcides | last post: by
1 post views Thread by shapper | last post: by
1 post views Thread by Steve Gerrard | last post: by
2 posts views Thread by shapper | last post: by
5 posts views Thread by Seb | last post: by
14 posts views Thread by thj | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.