LINQ to Dataset WHERE clause NULL reference exception?

If what you're asking is how to count the number of records where the joined table is null, then give this a try int tmp1 = ( from n in dt_query join m in dt_query2 on n. Field("VC_CLIENT_MAXID") equals m. Field("VC_CHAT_MAXID") into nm from LeftJoinM in nm.DefaultIfEmpty() where LeftJoinM == null select n.

Field("VC_CLIENT_MAXID") ).Count() If I misunderstood you, please let me know in a comment and I'll be happy to update.

If what you're asking is how to count the number of records where the joined table is null, then give this a try. Int tmp1 = ( from n in dt_query join m in dt_query2 on n. Field("VC_CLIENT_MAXID") equals m.

Field("VC_CHAT_MAXID") into nm from LeftJoinM in nm.DefaultIfEmpty() where LeftJoinM == null select n. Field("VC_CLIENT_MAXID") ).Count(); If I misunderstood you, please let me know in a comment and I'll be happy to update.

This is worked for me (this time)! But I have something to ask you. What does "m == null" means?

I think filter out the NULL in the specified column didn't work with this (Because I can't tell which column I checked for NULL anyway). What if the table A has VC_CLIENT_MAXID to join and VC_CHAT_STAFF from table B is NULL from the start? I think I will get wrong answer?

– dekhadmai Jun 3 '09 at 4:38 I've renamed m to "LeftJoinM" to make it a little clearer. "m == null" or now "LeftJoinM == null" basically checks to see if the join failed. It returns all records that could NOT be joined.

– Michael La Voie Jun 3 '09 at 5:57 SELECT COUNT(*) FROM VC_CLIENT LEFT JOIN VC_CHAT ON VC_CLIENT_MAXID = VC_CHAT_MAXID WHERE VC_CHAT_STAFF IS NULL > My point is "m == null" is not the perfect answer to translate this query. As you can see, if VC_CHAT has VC_CHAT_STAFF null data in it, I can't select it out because "m == null" can provide me only rows which the join failed. Am I right?

What will you translate this query into LINQ syntax? Because I get NullException when I tried calling "m. Field("VC_CHAT_STAFF")" in WHERE clause Anyway, thanks very much about your above answer.It helps me much!

– dekhadmai Jun 3 '09 at 7:14.

I have not tested the following code..Hope this should work int tmp1 = ( from n in dt_query join m in dt_query2 on n. Field("VC_CLIENT_MAXID") equals m. Field("VC_CHAT_MAXID") into nm from temp in nm.

Where(t => t. Field("VC_CLIENT_MAXID") ==null).DefaultIfEmpty() select VC_CLIENT_MAXID= (temp== null)? "" :n.

Field("VC_CLIENT_MAXID"); ).Count().

I wrote a comprehensive article addressing this very question; it was just published on Simple-Talk.com (LINQ Secrets Revealed: Chaining and Debugging) in December, 2010. I talk about LINQPad (as mentioned earlier by OwenP) as a great tool external to Visual Studio. Pay particular attention to its extraordinary Dump() method.

You can inject this at one or more points in a LINQ chain to see your data visualized in an amazingly clean and clear fashion. (1) Inject calls to the Dump() extension method I present in my article to allow logging. I started with Bart De Smet's Watch() method in his informative article LINQ to Objects – Debugging and added some labeling and colorization to enhance the visualization, though still it pales in comparison to LINQPad's Dump output.

(2) Bring LINQPad's visualization right into Visual Studio with Robert Ivanc's LINQPad Visualizer add-in. Not sure if it was through my prodding :-), but the couple inconveniences present when I was writing my article have now all been admirably addressed in the latest release. It has full VS2010 support and lets you examine any object you like when debugging.

(3) Embed nop statements in the middle of your LINQ chain so you can set breakpoints, as described earlier by Amazing Pete. In my article I provide a plethora of illustrations and code samples that lets you experience each of these approaches and more. I borrowed parts of this answer from another SO answer I provided; the question Debugging LINQ Queries covers eseentially the same ground.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions