Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Doing Complex Multi Joins in Linq

Posted on 2009-04-08
11
Medium Priority
?
257 Views
Last Modified: 2013-11-11
I'm trying to get this linq query to work, but its not returning any data. Unfortunately I do need to join all those tables to get my desired data. A similar query using Sql does work with the same set of joins (of course syntax is different though).
from c in hs.Computer
join tcp in hs.TCP on c.Computer_Idn equals tcp.Computer_Idn
join cs in hs.CompSystem on c.Computer_Idn equals cs.Computer_Idn
join ns in hs.NetworkSoftware on c.Computer_Idn equals ns.Computer_Idn
join p in hs.Processor on c.Computer_Idn equals p.Computer_Idn
join mem in hs.Memory on c.Computer_Idn equals mem.Computer_Idn
join ms in hs.MemorySlot on c.Computer_Idn equals ms.Computer_Idn
where c.DeviceName.Contains(wkstn)
select new Hardware
{
     DeviceName = c.DeviceName,
     Type = c.Type,
     LoginName = c.LoginName,
     FullName = c.FullName,
     HWLastScanDate = (c.HWLastScanDate == null ? DateTime.MinValue : (DateTime)c.HWLastScanDate),
     DomainName = c.DomainName,
     ComputerLocation = c.ComputerLocation,
     LDAPLocation = c.LDAPLocation,
     SerialNum = cs.SerialNum,
     Model = cs.Model,
     Manufacturer = cs.Manufacturer,
     Cpu = p.Type,
     Speed = (p.Speed == null ? 0 : (int)p.Speed),
     TotalMemoryMB = (mem.BytesTotal == null ? 0 : (int)mem.BytesTotal) / 1024,
     MemorySlotNo = ms.SlotNo,
     SizeInstalledMemory = (ms.InstalledSize == null ? 0 : (int)ms.InstalledSize),
     ChassisType = cs.ChassisType,
     IsLaptop = cs.HasBattery,
     NicAddress = ns.NicAddress
}

Open in new window

0
Comment
Question by:dharric08
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
11 Comments
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102224
shouldn't it  be for 'where' as :
....
where c.DeviceName.Contains(wkstn)
select new
{
     DeviceName = c.DeviceName,....
0
 

Author Comment

by:dharric08
ID: 24102336
Well here's a few points. I'm using the entity framework and creating a new Hardware object. And Vs does not give any compile or runtime errors whatsoever. It just doesn't return anything.
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102505
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102516
sorry blank comment:   Yes all looks good for me.
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102597
nope.. all looks good for me.  
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102611
Ok seems problems with DateTime.MinValue - 'DateTime.MinValue underflow in SQL Server'
for test: change DateTime.MinValue to some fixed date and give a try.

0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 2000 total points
ID: 24102639
use SqlDateTime.MinValue instead DateTime.MinValue and give a try
0
 

Author Comment

by:dharric08
ID: 24102672
Sree_ven, you're good! Now that you said it it seems so obvious. But what I don't get is there's no errors on compile or runtime. Shouldn't I have gotten a SqlDateTime overflow or something? Do you know why that is?
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102726
For your info:
The reason for the overflow is because .NET framework can cover a wider range of date than SQL Server. The DateTime structure in .NET supports a range from 0:00 1/1/0001 (MinValue) to 23:59 12/31/9999 (MaxValue). Whereas, SQL Server can only support a range of 1/1/1753 to 12/31/9999. Other databases handle datetime range differently.
0
 

Author Comment

by:dharric08
ID: 24102748
That's cool, but what I don't get is why I got no errors of any kind either during compile or at runtime. Could this be because of the Entity Framework layer hiding it?
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24102769
it raises SqlException : System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
Try putting your code in Try catch and catching SqlExceptions.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question