简体   繁体   English

实体框架Lambda表达式中的参数规范

[英]Parameter specification in entity framework lambda expression

Is there a different between the two statements below, perhaps in terms of performance or readability, assuming you have a model named RateCountry with CountryCode as one of the properties. 假设您有一个名为RateCountry且具有CountryCode作为属性之一的模型,以下两个语句之间在性能或可读性方面是否有所不同。 Of course in my project I will only have one return statement 当然在我的项目中,我只会有一份退货单

public RateCountry GetRateCountry(string countryCode, int rateId)
{
    return _directConnectContext.RateCountries.FirstOrDefault(rc => rc.CountryCode == countryCode && rc.RateID == rateId);

    return _directConnectContext.RateCountries.Where(rc => rc.CountryCode == countryCode && rc.RateID == rateId).FirstOrDefault(); 
}

Equality of LINQ statements is defined by equality of generated SQL code. LINQ语句的相等性由生成的SQL代码的相等性定义。 If you look at generated SQL code of both queries, you will see that they are the same. 如果查看两个查询的生成的SQL代码,您将看到它们是相同的。 So, answering your question - no, there is no difference. 因此,回答您的问题-不,没有区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM