开发者

Performance Question : Entity Framework

I have a static method in my DataLayer GetCompany. I made it because i need a company object to be compared with the property. The question is for the following code should i make another object and assign the returned Company Object to it or just use that in the conditions.

Which is the best way according to performance.

if (property != null && property.CompanyNum > 0)
{
    if (property is PersonalDetail &&
        (Property.GetCompany(property.CompanyNum)).
            CompanyType.ToUpper() != "COI")
    {
        if (property.TaxSubTypeId != 19)
        {
            if (property.CompanyNum == 81 && property.TaxSubTypeId == 11)
            {
                // Tax Sub Type of Compressor & Company Name
                // Midcon Compression LLC 
                SetPersonalNonCOI81Inputs();
            }
        }
    }
}

I have many conditions below so I am just me开发者_Python百科ntioning couple of them just let me know if how can I optimize it.


This sounds like a case of premature optimization. If your GetCompany method is not being called very often, then you have nothing to worry about.

However, from your listing, it appears that the Property.GetCompany call may be going out to a database to retrieve comapny information, so if you are calling this method many times per user request, then it may make sense to cache the return value in the code that is accessing this property.

Another issue that you may have is that your call to SetPersonalNonCOI81Inputs is likely modifying some global state value, since it is being called from your static GetCompany method. This will cause problems in a multi-threaded environment (assuming this is a web application), because you can have concurrent modifications to the shared state value. So, you may want to remove the SetPersonalNonCOI81Inputs method and simply return a new object there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜