简体   繁体   中英

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. 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. If you look at generated SQL code of both queries, you will see that they are the same. So, answering your question - no, there is no difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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