作爲LINQ新手,我創建了幾個查詢,並希望將它們合併爲一個,但我不知道如何去做。在這裏,他們是:如何將這些linq查詢合併爲一個?
var u = dc.Users.Where(w => w.UserName == userName).SingleOrDefault();
var m = dc.Memberships.Where(w => w.UserId == u.UserId).SingleOrDefault();
m.PasswordQuestion = securityQuestion;
m.PasswordAnswer = securityAnswer;
dc.SubmitChanges();
dc.Users
是aspnet_Users
表
dc.Membership
是aspnet_Membership
表
而且,是什麼SingleOrDefault
和FirstOrDefault
之間的區別?
你的第二個問題是重複的:http://stackoverflow.com/questions/1745691/linq-when-to-use-singleordefault-vs-firstordefault-with-filtering-criteria – 2010-01-23 00:17:07