Please help me convert a Linq Query to a SQL Query… Desperate?

If I understand correctly, you're trying to do an update query First, if you can use Jon Skeet's suggestion and you're more comfortable with LINQ, then go for it. The SQL equivalent should be something like UPDATE info SET gens. Owner_User_ID = item.

User_ID gens. Last_Login_For_Province = item. Last_Login_Province FROM Utopia_Province_Infos as info INNER JOIN Utopia_Province_Data_Captured_Gens as gens ON info.

Province_ID = gens. Province_ID This query joins two tables, making each row a "long" one that contains both tables. It proceeds to update some of the fields in each row You set the rest of Utopia_Province_Data_Captured_Gens's fields the same way as with User_ID.

You do the same replacing Utopia_Province_Infos with Utopia_Province_Identifiers for the second table in your code Note: I did not take into account your usage of FirstOrDefault You can set default value directly in Utopia_Province_Infos, or simply update values that have not been set (using a where clause). About the 'First' - is there more than one row with the same Province_ID in Utopia_Province_Infos? Why are you going for the first?

If I understand correctly, you're trying to do an update query. First, if you can use Jon Skeet's suggestion and you're more comfortable with LINQ, then go for it. The SQL equivalent should be something like - UPDATE info SET gens.

Owner_User_ID = item. User_ID gens. Last_Login_For_Province = item.

Last_Login_Province FROM Utopia_Province_Infos as info INNER JOIN Utopia_Province_Data_Captured_Gens as gens ON info. Province_ID = gens. Province_ID This query joins two tables, making each row a "long" one that contains both tables.It proceeds to update some of the fields in each row.

You set the rest of Utopia_Province_Data_Captured_Gens's fields the same way as with User_ID. You do the same replacing Utopia_Province_Infos with Utopia_Province_Identifiers for the second table in your code. Note: I did not take into account your usage of FirstOrDefault.

You can set default value directly in Utopia_Province_Infos, or simply update values that have not been set (using a where clause). About the 'First' - is there more than one row with the same Province_ID in Utopia_Province_Infos? Why are you going for the first?

– Scott Dec 29 '09 at 16:19 The query does that itself. – Jon Skeet Dec 29 '09 at 16:23 Thank you Asaf! You saved my life!

– Scott Dec 29 '09 at 19:36 @Scott my pleasure. – Asaf R Dec 29 '09 at 7:42.

Well, you should be doing a join in the first place - currently you're executing two extra queries for each row of the table, which is incredibly inefficient. Here's an example of the join: var results = from xx in db. Utopia_Province_Data_Captured_Gens join yy in db.

Utopia_Province_Infos on xx. Province_ID equals yy. Province_ID select new { item = xx, updateItem = yy }; foreach (var result in results) { result.item.

Owner_User_ID = result.updateItem. User_ID; result.item. Last_Login_For_Province = result.updateItem.

Last_Login_Province; result.item. Date_Time_User_ID_Linked = result.updateItem. Date_Time_Added; result.item.

Added_By_User_ID = result.updateItem. Added_By_User_ID; } // Ditto for second query Note that this will update all items with matching Province_IDs rather than just the first one, but I would guess that these are the primary keys anyway, so it won't be a problem. EDIT: I should note that Asaf's solution is a preferable in terms of efficiency.

There's no point in fetching all the data back to the client when the database can do it all itself.

I can only imagine Linqpad still not being able to handle this and erroring out... Errors usually come with the out of memory exception... – Scott Dec 29 '09 at 7:57 you are correct, the province_Id'sare the Guid primary keys. – Scott Dec 29 '09 at 7:58 When you say "I can only imagine" - have you tried it? – Jon Skeet Dec 29 '09 at 10:18 I have now and it didn't actually work...It errored out.

– Scott Dec 29 '09 at 16:17 With what error? – Jon Skeet Dec 29 '09 at 16:22.

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.

Related Questions