草庐IT

host-context

全部标签

c# - 关于Entity Framework Context Lifetime的问题

我对ASP.NETMVC应用程序中EntityFramework上下文的预期生命周期有一些疑问。在尽可能短的时间内保持上下文事件不是最好的吗?考虑以下Controller操作:publicActionResultIndex(){IEnumerablemodel;using(varcontext=newMyEntities()){model=context.MyTable;}returnView(model);}上面的代码将不起作用,因为EntityFramework上下文在View呈现页面时超出了范围。其他人会如何构造上面的代码? 最佳答案

c# - 使用 Entity Framework 添加具有读/写操作和 View 的 Controller - "Data Context class"是什么?

所以在VisualStudio中,当我去添加一个Controller时,我得到这个对话框:我很好奇如果我在使用EF时选择“具有读/写操作和View的Controller,使用EntityFramework”,VisualStudio会创建什么。所以我将我的模型类设置为创建的View模型,为我的View选择了Razor,但我不知道数据上下文类是什么?下拉列表中唯一的内容是我创建的View模型。 最佳答案 DataContext类是顶级EF对象,它包含映射到数据库表的所有实体集合。Controller需要能够访问它,以便它可以执行CRU

c# - Nancy Self Host 不调用 Module?

我正在努力将NancyFramework添加到我的C#控制台应用程序(遵循非常简短的教程here,当我转到http://localhost:1234时它会加载一个空白页面,所以我知道它正在启动,但它没有显示我的文本正确。我已经多次检查我的代码,但没有发现任何问题。我已将Nancy和Nancy.Hosting.Self添加到我的项目中。staticvoidMain(string[]args){varnancyHost=newNancy.Hosting.Self.NancyHost(newUri("http://localhost:1234"));nancyHost.Start();Con

c# - Entity Framework 核心 : Log queries for a single db context instance

使用EFCore(或与此相关的任何ORM)我想跟踪ORM在我的软件中的某些操作期间对数据库进行的查询次数。我之前在Python下使用过SQLAlchemy,在那个堆栈上,这很容易设置。我通常有单元测试,这些单元测试针对内存中的SQLite数据库断言针对场景进行的查询数量。现在我想使用EFCore做同样的事情,并查看了Loggingdocumentation.在我的测试设置代码中,我按照文档所述进行操作:using(vardb=newBloggingContext()){varserviceProvider=db.GetInfrastructure();varloggerFactory=

c# - "The SMTP host was not specified."- 但它是指定的?

我在这里有点困惑-我收到以下错误:TheSMTPhostwasnotspecified.即使我的代码看起来是正确的(据我所知)。我可以通过在Controller中包含所有详细信息来手动完成此操作,例如SmtpClientsmtpClient=newSmtpClient("smtp.gmail.com");smtpClient.Port=587;...etc但我不必这样做,因为我想使用mailSettings中的详细信息(使其可重复用于各种不同的Controller)。mailSettings在我的Web.Config文件中:我的Controller操作:[HttpPost]public

c# - Response.OutputStream.Write 中的 "The remote host closed the connection"

此代码将大文件流式传输给我们的用户://Openthefile.iStream=newSystem.IO.FileStream(filepath,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);//Totalbytestoread:dataToRead=iStream.Length;//Readthebytes.while(dataToRead>0){//Verifythattheclientisconnected.if(Response.IsClientConnected){//R

c# - 无效操作异常 : Cannot create a DbSet for 'Role' because this type is not included in the model for the context

以下解决方案适用于.netcore1.1,但从1.1升级到2.0后,我收到以下错误:InvalidOperationException:CannotcreateaDbSetfor'Role'becausethistypeisnotincludedinthemodelforthecontext.当用户尝试登录并执行以下语句时:varresult=await_signInManager.PasswordSignInAsync(model.Email,model.Password,model.RememberMe,lockoutOnFailure:false);怎么了?User.cspubl

docker - 将 --net=host 传递给 docker build

要将其他选项传递给dockerbuild,您可以在/etc/default/docker中指定DOCKER_OPTS,但是--net不是可用的。构建容器时是否可以使用主机的网络堆栈?我正在运行Docker版本1.3.2,构建39fa2fa。谢谢! 最佳答案 尝试使用--network而不是--net。它是1.25API和setsthenetworkingmodefortheRUNinstructions中的新功能. 关于docker-将--net=host传递给dockerbuild,我

docker - 将 --net=host 传递给 docker build

要将其他选项传递给dockerbuild,您可以在/etc/default/docker中指定DOCKER_OPTS,但是--net不是可用的。构建容器时是否可以使用主机的网络堆栈?我正在运行Docker版本1.3.2,构建39fa2fa。谢谢! 最佳答案 尝试使用--network而不是--net。它是1.25API和setsthenetworkingmodefortheRUNinstructions中的新功能. 关于docker-将--net=host传递给dockerbuild,我

C# 编译器 : cannot access static method in a non-static context

我有下面的代码:publicclassAnything{publicintData{get;set;}}publicclassMyGenericBase{publicvoidInstanceMethod(Tdata){//dosomejob}publicstaticvoidStaticMethod(Tdata){//dosomejob}//othersmembers...}publicsealedclassUsefulController:MyGenericBase{publicvoidProxyToStaticMethod(){StaticMethod(null);}//others