Thanks again
void Main()
{
string con = @"Data Source=DEVELOPMENT2\SQLSERVER2008;Initial
Catalog=PathWestStaff;Integrated Security=True";
DataContext db = new DataContext(con);
//var permissions = db.GetTable<Admin>();
//var stafflist = db.GetTable<Staff>();
var query =
from staffmember in db.GetTable<Staff>()
from authorization in staffmember.Admins
where staffmember.HE_Number.Contains("he002703")
select authorization;
var individual = query.FirstOrDefault() ?? new Admin();
//if(individual == null) individual = new Admin();
individual.Dump();
}
Regards Peter Maddin
Applications Development Officer
PathWest Laboratory Medicine WA
Phone : +618 6396 4285 (Monday, Wednesday,Friday)
Phone : +618 9346 4372 (Tuesday, Thursday)
Mobile: 0423 540 825
E-Mail : [email protected]; [email protected]
The contents of this e-mail transmission outside of the WAGHS network are
intended solely for the named recipient's), may be confidential, and may be
privileged or otherwise protected from disclosure in the public interest.
The use, reproduction, disclosure or distribution of the contents of this
e-mail transmission by any person other than the named recipient(s) is
prohibited. If you are not a named recipient please notify the sender
immediately.
From: [email protected] [mailto:[email protected]]
On Behalf Of Mark Hurd
Sent: Wednesday, 28 March 2012 6:10 PM
To: ozDotNet
Subject: Re: Very simple LINQ query
On 28 March 2012 19:16, Peter Maddin <[email protected]> wrote:
Great!
Thanks every one for their suggestions
This works well
<snip>
var individual = query.FirstOrDefault();
if(individual == null) individual = new Admin();
All of your samples have this. In VB.NET there is the two-valued If
statement that can simplify this to
Dim individual = If(query.FirstOrDefault, New Admin())
I believe the C# equivalent is
var individual = query.FirstOrDefault()??(new Admin());
--
Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)