473,321 Members | 1,877 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,321 software developers and data experts.

LINQ Help

Hi
I an newbie to LINQ.

I have a dataset with one table employee which has a self referencing
foreign key manger id. I want to write a query to get all the employees
under a particular manager. I tried the following query

var results = from e in emp.employee
where e.employeeRowParent.name == "Doe"
select e;
but when I run this I get a null ref exception in the where. How should
I rewrite this query ?
Nov 13 '07 #1
2 1297
Satish <si*********@clayton.comwrote:
I an newbie to LINQ.

I have a dataset with one table employee which has a self referencing
foreign key manger id. I want to write a query to get all the employees
under a particular manager. I tried the following query

var results = from e in emp.employee
where e.employeeRowParent.name == "Doe"
select e;
but when I run this I get a null ref exception in the where. How should
I rewrite this query ?
Well, it looks like the employeeRowParent is null - how about:

var results = from e in emp.employee
where e.employeeRowParent != null &&
e.employeeRowParent.name == "Doe"
select e;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '07 #2
Thanks Jon that works.
Jon Skeet [C# MVP] wrote:
Satish <si*********@clayton.comwrote:
>I an newbie to LINQ.

I have a dataset with one table employee which has a self referencing
foreign key manger id. I want to write a query to get all the employees
under a particular manager. I tried the following query

var results = from e in emp.employee
where e.employeeRowParent.name == "Doe"
select e;
but when I run this I get a null ref exception in the where. How should
I rewrite this query ?

Well, it looks like the employeeRowParent is null - how about:

var results = from e in emp.employee
where e.employeeRowParent != null &&
e.employeeRowParent.name == "Doe"
select e;
Nov 13 '07 #3

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

Similar topics

4
by: Dave Johnson | last post by:
Greetings, i want to be able to use linq new technology with sql server. the senario i am not able to do so far is as follow: 1- i program with linq 2- be able to generate and manipulate...
4
by: cj | last post by:
Can I use LINQ in VB .Net 2008 to get to a Visual FoxPro Table? I've seen demos of it with SQL Server but they've used it with a server browser and I don't think that'd work when I need to see VFP...
8
by: Andy | last post by:
Hi, I'm trying to add a where clause to my query: List<stringtypes = new List<string>(); types.Add( "A" ); types.Add( "B" ); query = query.Where( c =types.Contains( c.Type ) );
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
4
by: Jacek Jurkowski | last post by:
Why is it so slow? I really like that queries but using DataReader i have done my task's much more faster than ising LINQ...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
2
by: Tom P. | last post by:
I'm not getting the theory behind LINQ, and without that I can't get my head around how to use it and why. Here's what I _think_ I'm trying to do: I've got a menu with several items. Some other...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
0
by: hrishy | last post by:
Hi Tim I am not a LINQ expert just a LINQ user and (was a little envious why the langauge i fantasize doesnt have it (pardon my ignorance of python)) LINQ as far as i know allows you to query...
2
by: shapper | last post by:
Hello, I have the following Linq query: List<PostsTaginsert = (from t in (from t in database.Tags join p in paper.Tags on t.Name equals p.Name select t).ToList() select new PostsTag {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.