LINQ DataContext.SubmitChanges () in C # Reporting "Object reference not set to object instance."

I think many people had this problem, but I cannot fix it or understand why I have it. I tore off my hair for a couple of hours.

I get an error: "The reference to the object is not installed in the instance of the object." to my datacontext.SubmitChanges () the second time this method is started (I iterate over the ObjectName rowset):

    private Object CreateObject(string ObjectName, SystemClassEnum SystemClass)
    {
        Object result = new Object();
        result.Name = ObjectName;
        result.SystemClassID = (int)SystemClass;
        _dataContext.Objects.InsertOnSubmit(result);
        _dataContext.SubmitChanges();
        return result;
    }

I thought this was because the value of result.Name might be null, but I don't think anymore.

Seems something DataContext is closing? but in debug mode, I will check the connection status and "Open" after an error occurs.

I am using the repository pattern and ASP.NET MVC.

(new Object()) LINQ DBML, , . , .

.

? , .

,

Eric

+3
1

Object - ; ... ... ( System ..).

, (_dataContext.Objects. ..)? , - , _dataContext (, null), , () - partial data-context entity, - . , .

+2

Source: https://habr.com/ru/post/1719485/


All Articles