473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4031
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rouben Rostamian | last post by:
I searched the C99 standard and clc's FAQ but was unable to find an answer to the following issue. I hope that someone here can illuminate me. Suppose I have: enum myenum { enuma, enumb,...
12
by: Charlie | last post by:
I have a file, data.c, where I define all of my global variables. I then have a header file, data.h, which I include in every file in which I reference all of the variables defined in data.c. ...
8
by: Alcides | last post by:
Hello all, I learn about LINQ here in this forum. I been a VB.NET programmer for quite a while and we are using an internal solution for SQL access. I have some experience with C# and I started...
1
by: shapper | last post by:
Hi, I wonder, is there some tool that transforms SQL procedures to LINQ? :-) I want to use LINQ but I have so much work done in SQL that would be great to transform my SQL code to LINQ. ...
1
by: Steve Gerrard | last post by:
Roshawn wrote: I could be way off, so take this with a grain of salt. I would first remove the (0) after Products; then I would specify a property for myMerchant, i.e. name. That would give...
2
by: shapper | last post by:
Hello, I am using the following Linq Query: var filter = (from t in database.Tags where t.Name.StartsWith(q, StringComparison.CurrentCultureIgnoreCase) orderby t.Name select t);
5
by: Seb | last post by:
I want to count activity in a given month. I'm trying to do so with the linq code below however it reports: Error 1 'a' is inaccessible due to its protection level var ActivityByMonths = from a...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
8
by: benn | last post by:
Here's the setup... Defines.h file contains: enum DAY { monday, tueday }; DayFunctions.h contains prototype: void printIsMonday ( enum DAY currentDay); DayFunctions.c contains:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.