473,398 Members | 2,403 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,398 software developers and data experts.

... has no supported translation to SQL.

Hello,

I am creating a int value has follows:

int result = db.Posts.Where(p =p.IsPublished == true &&
CheckPostDate(s.CreatedAt).GetValueOrDefault(false ) == true).Count();

I get the error:
Method 'System.Nullable`1[System.Boolean]
CheckPostDate(System.Nullable`1[System.DateTime])' has no supported
translation to SQL.

Can't I call a function I created in a Linq query?

How can I solve this problem?

Thanks,
Miguel

Oct 20 '08 #1
3 5979
lol! OK, in this case, stick to null-coalescing (??) ;-p

Fair cop - but it would have worked with LINQ-to-Objects...

Sorry for any confusion...
Oct 20 '08 #2
On Oct 20, 11:37*am, Marc Gravell <marc.grav...@gmail.comwrote:
lol! OK, in this case, stick to null-coalescing (??) ;-p

Fair cop - but it would have worked with LINQ-to-Objects...

Sorry for any confusion...
You mean:

int result = db.Posts.Where(p =p.IsPublished == true (&&
CheckPostDate(s.CreatedAt) ?? false)).Count();

I still get the same error. I don't think that's the problem.
Oct 20 '08 #3
Ah, right - I thought the GetValueOrDefault was the issue. Indeed, you
can't use a regular method (CheckPostDate) in LINQ, *unless* that method
can be mapped to a UDF at the database. In which case, you need to mark
the method with the [FunctionAttribute], supplying the UDF (etc) and
marking the function as "composable".

Here's a trivial example:

[Function(Name="NEWID", IsComposable=true)]
public Guid Random()
{ // to prove not used by our C# code...
throw new NotImplementedException();
}

At the DB this will become TSQL calling NEWID() - but you can have
parameters etc as you need.

Noet that this only works with some LINQ providers (I belive LINQ-to-SQL
supports it, EF doesn't), and the method needs to be on the data-context.

Marc
Oct 20 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt | last post by:
Short Description: The Translation Hub is not picking up the TNS names file. I'm using Oracle 9ids. It doesn't work for any users and it has never worked since it's been installed. Long...
40
by: Chiwa | last post by:
Hey, Expression: Math.floor(x * 100) / 100 x= 4.1 gives 4.09, why in gods name? While other values for x don't give a problem. Thx in advance
5
by: Haines Brown | last post by:
I suspect this is a FAQ, but as a guide to my further investigation, I wondered what the options are for providing readers of my web pages with the ability to translate the pages into their own...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
2
by: Arne Adams | last post by:
Hi, the following does not compile with VC7.1 (and I think it should according to the C++ Standard (1998)) template<class T> struct SpecializeStaticMember { static int m_Num; }; //...
12
by: Peter Oliphant | last post by:
At the following link: http://msdn2.microsoft.com/en-us/library/b23b94s7 there is the following quote near the top of the page (pay special attention to the last sentance): "For Visual C++...
9
by: Martin Wells | last post by:
Is there anything like __inline_is_supported to indicate whether a certain C compiler supports inline? I'm writing my code as fully portable C89, but I want to use inline. Martin
1
by: deerchao | last post by:
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...
0
by: Stef Mientki | last post by:
hello, I've build a translation tool, to translate all strings in a python source file. As a extra gadget I added translation through Babel Fish, using beautifulsoup. Although it works...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.