(select customer_id from cust where username=name)
万千封印
浏览 180回答 3
3回答
慕哥9229398
所以你有两张桌子:一张Cust桌子和一张Customer桌子。两个表都有一个属性CustomerId。该Cust表也有一个属性UserName。现在给定一个字符串变量name,您希望Customers表中具有CustomerId等于CustomerId的所有元素在Cust表中具有UserName等于的所有元素中name。对我来说似乎是一个加入:var result = myDbContext.Cust // take the cust table .Where(cust => cust.UserName == name) // keep only custs with Username == name .Join(myDbContext.Customers, // Join the result with Customers table cust => cust.CustomerId, // From every cust take the CustomerId customer => customer.CustomerId, // From every customer take the CustomerId (cust, customer) => // when they match take the cust and the Customer customer // to select the matching Customer