I need to query a database and get a single record back or an empty record.
I know this is not too hard, but I also need to get back a named object and
not an anonymous one.
I want to persist this in session state for an asp.net application so I need
something that can be serialized.
Using LINQPad this is something what I am trying to achieve
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 authorization in permissions
join staffmember in stafflist
on authorization.StaffId equals staffmember.StaffId
where staffmember.HE_Number.Contains("he1234567")
select authorization;
query.Dump();
}
The above works but I need to get a single named instance I can store in
session state and would like to use the DefaultIfEmpty() extension when
there is no record.
I think I need to use an outer rather than an inner join.
I was hoping that a LINQ expert could fast track me here.
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.