Techaray

Shailendra Saxena's Technical Blog

New transaction is not allowed because there are other threads running in the session

clock February 25, 2014 05:45 by author ShailendraSaxena

Error: New transaction is not allowed because there are other threads running in the session in entity framework.


Code: Where Error was coming

                        foreach (Objects Objtmp in tblObj)
                        {
                            ObjectMapping tblObjMap = new ObjectMapping
                            {
                                companyid = TblComp.CompanyId,
                                ObjectID = Objtmp.ObjectID,

                            };
                          
                            db.ObjectMapping.Add(tblObjMap);
                            db.SaveChanges();

 

Resolved Code : was as below.


                        var lstObj = tblObj.ToArray<Objects>();
                        
                        foreach(var lobj in lstObj)
                        {
                            ObjectMapping tblObjMap = new ObjectMapping();
                            tblObjMap.ObjectID= lobj.ObjectID;
                            tblObjMap.companyid=TblComp.CompanyId;
                            db.ObjectMapping.Add(tblObjMap);
                            db.SaveChanges();


                        }

 

What I did was I took the values of my search query into list variable and then do the updation.

 

 

 



Sequence contains no elements Linq

clock February 20, 2014 02:44 by author ShailendraSaxena

 

" Sequence contains no elements"

 

 

 

Error : While executing Linq Query error came as Sequence contains no elements.

 

Resolution: This error comes when you execute .First or .Single with LINQ Query because when no record is found then it throws exception.

 

So it is better to use . FirstOrDefault because in this case either record will be returned or null will be return.

 



There was an error running the selected code generator: MVC Entity Framework

clock February 6, 2014 08:16 by author ShailendraSaxena

Error : There was an error running the selected code generator

 

Above error comes in case of MVC project. when you have already created a separate DAL with Entity Framework 5.0 and you are adding this DAL in another project which is made in VS2013 with EF 6.0.

 

Resolution : To resolve this error I re-create my DAL Project with EF6.0 and add the reference in my Web Project.

 



ASP.NET Web Forms V/s ASP.net MVC

clock February 4, 2014 05:03 by author ShailendraSaxena



Search

Calendar

<<  June 2017  >>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

Archive

Tags

Categories


Visitors

FlagCounter

Flag Counter

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign In