خرید بک لینک

Vote count: 0

I have a very basic code using Entity Framework to get a model in my MVC C# .NET Controller.

var myModel = myContext.MyData
                .Where(m => m.ID == 1)
                .FirstOrDefault();

string json = Newtonsoft.Json.JsonConvert.SerializeObject(myModel);

When I try to run this code, I get an error:

Error getting value from 'ServerVersion' on 'System.Data.SqlClient.

... If I press 'Continue', the view says:

[InvalidOperationException: Invalid operation. The coection is closed.]

Whats wrong?? What does SQL have to do with this? The same error comes if I do this in the View instead of the Controller.

asked 5 mins ago

1 Answer

Vote count: 0

The underlying coection used by myContext seems to be closeddisposed.

Check where are you creating the DbContext and be sure that when you're calling your code it's in a valid state.

answered 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 26 بهمن 1394 ساعت: 20:05

صفحه بندی