I am working with LINQ To SQL
connection in my ASP.NET
website but I have some strange problems. I created Singleton entity of DataContext
for all of the using in the website but I don't really understand why the data not always updated and sometimes adding row to table failed because another entity with the same key already exists (I checked and that is no such entity).
What's the problem and there is another way to use this connection?
public class SQLConnection
{
private LearningDBDataContext dbDataContext;
public SQLConnection()
{
dbDataContext = new LearningDBDataContext();
}
public LearningDBDataContext GetDataContextInstance()
{
return dbDataContext;
}
public void reCreateDBConnection()
{
dbDataContext = new LearningDBDataContext();
}
}