Try this out, if anything it might give you an idea. My idea behind it is to use correlated subqueries a new anonymous type to store all the information you need. Check it out: var usernames = ((from e in db.
EmailAlerts select e. UserName). Union (from t in db.
TextAlerts select t. UserName)).Distinct(); var result = from you in usernames select new { Username = u. Username, ActiveType1Email = (from e in db.
EmailAlerts where e. UserName == you && e. Type == (int)AlertType.
Type1 && a. Description == "active" select e).FirstOrDefault(); /* ... and so on repeat for activeType1Text, activeType2Email and activeType2Text */ } // and then go trough the result set which is IEnumarable and use it for what you need foreach(var a in result) { var something = a. ActiveType1Email; /* etc.*/ } Does this provide any help to you?
Sorry, I was being unclear, will update my question with example tables. The user doesn't have to have a record in both tables. – annelie Mar 8 at 19:30 1 This looks nicer, I've been trying to make it into one or two big queries but this might be the best way to tackle it.
Thanks for you help! – annelie Mar 10 at 15:46.
I'm struggling to work out the best way to show a combined result from two unrelated tables using linq to sql (C#). The tables are EmailAlerts and TextAlerts, each with UserName, Type and Status (plus other columns that differ, but only need these three for this query). For reporting purposes, I need to get a snapshot of users who have an active alert in the system.
So, for each unique user, find out if they have an active (status = 0) email or text alert of either type.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.