using(DMS_GenericDataContext db = new DMS_GenericDataContext())
{
Document_Master doc1 = db.Document_Masters
.Where(c => c.Document_Id_Prefix == "PRD_TST_TST1_T2_" && c.Document_Id == "2")
.SingleOrDefault();
// If the record exists, then make the corresponding update.
if(doc1!=null)
{
doc1.User_IDD = "anuragnigam";
db.SaveChanges();
}
}
Try to use the using statement, when you use disposable objects like a DataContext. Also, you should use SingleOrDefault() rather than use Single(), because if you use the latter and there isn't any record like the one you are looking, you will get an exception. On the other hand, if you use SingleOrDefault(), you will not get an exception. If there isn't the record in the db, you will get a null object. Last but not least, you should check if the Document_Master isn't null. If it isn't, that mean that there exist the record in your db and you can make the corresponding update.