LINQ Optional Parameter not passing NULL correctly?

Asked By Nick S
02-Aug-10 09:45 AM
Earn up to 0 extra points for answering this tough question.
Hi,

I'm using LINQ in my application, and I have an optional int data type in my WCF web service.

So:

public List<Test> GetRecords(int seq1, int? seq2)

{

TestDataContext db = new TestDataContext ();

var myList = (from test in db.test

where test.SEQ_GROUP == seq1 && test.SEQ_STAFF == seq2
select new Test

{

Item = System.Convert.ToString(test.SEQUENCE),

ID = test.ID,

Description = test.DESCRIPTION,

Name = test.Name,

Desc = test.Desc

}

);


Now, if I execute this, the SQL basically queries the database and says SEQ_STAFF = 1

Howvever, if I don't populate seq2 as the optional integer... the SQL code executes as SEQ_STAFF = null

This should be executing SEQ_STAFF IS NULL


Can anyone help here?

THanks,

Nick

 

  re: LINQ Optional Parameter not passing NULL correctly?

Indranil Chatterjee replied to Nick S
03-Jan-11 06:24 AM
That is a common limitation of LINQ to SQL.
Try this instead:

from test in db.test

where test.SEQ_GROUP == seq1 && ((seq2 == null && test.SEQ_STAFF == null) || test.SEQ_STAFF == seq2)
select new Test

//The point is, when the comparison is explicitly done against null, LINQ to SQL generates a proper IS NULL clause

Create New Account
upload image to database , silverlight hi, in silverlight how can i upload image or file to database. i m using wcf service + LINQ for database connectivity. so how can i send the image to wcf service to upload. check this one explaining how to accomplish this. . http: / / silverlight.net / forums / t / 64867.aspx Hi, 1. WCF + LINQ: are you going to store the image / file to database of to a physcial location to the server? f or either methods, you can expose a method in WCF which would accept a byte array as argument. so that
Wpf, Wcf, Mvvm, Linq HI, How to insert the data into tables using wpf, wcf, mvvmpattern and linq Refer these- WPF MVVM Pattern: A Simple Tutorial for Absolute automated (see here) create a DataContext class that represents your database - you will need this to get and submit your changes to the database after you've made changes to your object model, submit the changes to the database using the data context. there are plenty of examples on library / bb425822.aspx#linqtosql_topic7 Regards. Create New Account keywords: Wpf, Wcf, Mvvm, Linq description: HI, How to insert the data into tables using wpf, wcf, mvvmpattern and linq
WCF Data Services / WCF Behaviors And Server Side Processing Server Side Processing of Data in WCF Data Services Using WCF Behaviors Introduction One of the concerns around the data services to control the outgoing data. Unfortunately, Entity Framework provider of WCF Data Services does not support processing data before forwarding to of Data Services. That approach uses the customized version of LINQ to SQL to do so. In this paper, I will approach processes the outgoing data using the facilities provided by WCF Behaviors. The advantage of using WCF behaviors is the fact that they deploy in a plug the outgoing data. The behavior raises an event whenever a WCF message has been sent to the clients. By capturing the In the next section, the concepts that are related to WCF Behaviors have been illustrated. In the last section I explain
WCF dataContracts and LINQ to SQL errors Iam trying to create a basic WCF service library web service which connects to a database via LINQ to SQL and returns list of DataContract marked objects but recieving this error: Error 1 Cannot implicitly convert type 'System.Linq.IQueryable<CwkServer.getCarDetails> ' to 'System.Collections.Generic.List<CwkServer.getCarDetails
Flat file Database with LINQ and ASP.NET jQuery Page Methods How to create a flat file delimited database of quotations and implement LINQ plus jQuery access to ASP.NET PageMethods. I've been keeping a database of famous (and not so famous) quotations for the last quotations in it. I also use it as a sample database for various articles that I've written. This time around to take a different tack. Instead of having a "normal" database with Author, Subject and Quotation tables, I decided to export a List of Quotation objects and be able to use LINQ to query it from memory. In this sample I'll I'm going to be doing all my querying via LINQ: public class Author :IEquatable<Author> { public string FirstName { get; set query operators such as Distinct will get correct results. The LINQ Distinct operator by itself is just not that smart - you
trying to binding treeview (hierarchicaldatatemplate treeview data binding) by using wcf and linq to sql my table is there and i want output is like in Silverlight By Database connectivity using wcf and linq to sql. Here is good sample for create dynamic treeview amp-hierarchaldatatemplate.aspx HI First take a look at the LINQ to SQL Object Relational Diagram from the Northwind database. In Example 1 & 2 we will use the Product , Category scipbe.wordpress.com / 2007 / 12 / 28 / article-wpf-treeviews-and-linq-to-sql / Hi Since the result of your query result
why wcf is required why wcf is required give me some example When you need any or object that should come from another application you use WCF or any other distributing system, advantages of WCF, •Its made of a lot of different components, so you Load Balancing •Its Interoperability, for java, and more. . Advantages of WCF? http: / / srinutamada1.wordpress.com / category / technology / advantages-of-wcf / In short WCF is a unification technology which unites the following technologies:- √ .NET remoting √ MSMQ √ Web services √ COM+. Below figure depicts WCF fundamentals pictorially. Long Long time a ago there lived a u Sir, i want this in interview patten. i know wcf i have to expalin it in interview so am asking of your question as is follows. . . 1. why we need WCF As the developer we are more focused on the business
Data Serilization problem during communicating through WCF service Hello All, I have a WCF service and there is a method which fetches some data from database through LINQ Query and returns IQuerable. When i am trying to access question correctly, you are directly returning the results from the LINQ query. However, WCF should be able to serialize these objects. Instead of returning of another type adorned with the DataContract attribute. This tells WCF to use the DataContractSerializer to serialize any instance of that int Id { get; set; } } After getting the results from the LINQ query, create an EmployeeData for each result, which you will then use as the return value of the WCF service operation. Create New Account