473,657 Members | 2,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.employeeRowPa rent.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 1305
Satish <si*********@cl ayton.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.employeeRowPa rent.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 employeeRowPare nt is null - how about:

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

--
Jon Skeet - <sk***@pobox.co m>
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*********@cl ayton.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.employeeRowPa rent.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 employeeRowPare nt is null - how about:

var results = from e in emp.employee
where e.employeeRowPa rent != null &&
e.employeeRowPa rent.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
1884
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 xml files 3- all this xml files are stored in Sqlserver
4
2151
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 tables.
8
46867
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
2896
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: tlkpColor (PK) tlkpColorID
4
1974
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
2357
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 occuring enough to be a real cause for concern. The errors occur a couple times a week and the website is hit with constant traffic 24x7. Below are the two errors that are encountered. I had read something about MARS causing errors like this but...
2
1438
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 part of the application is changing the text in a combobox and I want to set the indicator to the correct menuitem. I can loop through the Items collection and look at the Tag for my indicator, like so: foreach (ToolStripItem CurrentButton in...
4
2180
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 not reinsert it with a different revision number. Compounding the issue, we’ve also got an associated table storing properties for our entities which is not revisioned, but we still want changes to the children of our entity (additions, changes...
0
1545
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 all sources using a consistent interface . You can query a message queue ,xml document ,array object or relational source by learning LINQ and even join them as illustrated below http://informationr.net/ir/13-2/TB0806.html
2
2394
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
8397
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.