Open GoogleCodeExporter opened 8 years ago
[deleted comment]
What actually is that when i use Nancy Razor view engine, after i GetList from
the table to the model, then past it to view it is error when using IEnumerable
but it works when using List. I think because of the Lazy Loading when i use
IEnumerable, the connection was closed before render in view.
// In my DepartmentModule.cs
Get["/"] = p =>
{
IEnumerable<Department> department = db.GetList<Department>(); // error
IList<Department> department = db.GetList<Department>().ToList(); // work
return View["department", department];
};
// in BaseModules.cs
public class BaseModule: NancyModule
{
public dynamic Model = new ExpandoObject();
protected IDbConnection db;
public BaseModule()
{
SetupDefaults();
}
public BaseModule(string modulePath): base(modulePath)
{
SetupDefaults();
}
private void SetupDefaults()
{
Before.AddItemToEndOfPipeline(ctx =>
{
Model.Master = new MasterModel();
return null;
});
Before += ctx =>
{
var conString = System.Configuration.ConfigurationManager.ConnectionStrings["dbString"].ToString();
db = new SqlCeConnection(conString);
db.Open();
return null;
};
After.AddItemToEndOfPipeline(ctx =>
{
if (db.State == ConnectionState.Open)
db.Close();
});
}
}
And i am very much appreciated if you can give me the sample of the code.
Original comment by vuth...@gmail.com
on 13 Sep 2012 at 10:49
Original issue reported on code.google.com by
vuth...@gmail.com
on 13 Sep 2012 at 8:31