开发者

Using static data access methods with the ADO.NET Entity Framework

Hi I am using the ADO.NET entity framework for the first time and the staticcode analysis is suggesting I change the following method to a static one as below.

My question is simple, is this thread safe?

public static void InsertUserDetails(UserAccount userAccount)
        {
            using (KnowledgeShareEntities entities = new KnowledgeShareEntities())
            {
                Users user = new Users();
                user.usr_firstname = userAccount.FirstName;
                user.usr_surname = userAccount.LastName;
                user.usr_email = userAccount.Contact.Email;
                user.usr_logon_name = userAccount.SAMUserAccountName.ToUpper();
                user.usr_last_login_datetime = DateTime.Now;
                entities.开发者_如何转开发AddToUsers(user);
                entities.SaveChanges();
            }
        }


As you are using only local variables the method is thread safe. There are no static variables involved so everything will be on the thread local stack and no race conditions could occur.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜