update query in linq to sql

update query in linq to sql

Hi Everyone,

I'm going to share the code sample for update query in linq to sql in c# asp.net

Today, I have a requirement to update the log details in the DB with respect to the UserId.

 /// <summary>
 /// Update to user device access log table using linq to sql in c# .net

 /// </summary>
 using (ExceptionLogDataContext dbContext = new ExceptionLogDataContext())
     if (!string.IsNullOrEmpty(UserId))
        var IsExistedUser = (from user in dbContext.UserDeviceAccessLogs
              where user.UserId == Convert.ToInt32(UserId)
              select user).FirstOrDefault();

        if (IsExistedUser.UserId != null)
                  IsExistedUser.CreatedDate = DateTime.UtcNow;
                  IsExistedUser.DeviceType = DeviceType;
                  IsExistedUser.LastAccessed = DateTime.UtcNow;
                  IsExistedUser.LatestAccessIP = AccessIPAddress; 



Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book