【c# – 在UITypeEditor的EditValue中访问其他上下文数据】教程文章相关的互联网学习教程文章

c# – 上下文在Code First模式下使用,代码是从EDMX文件生成的,用于Database First或Model First开发【代码】

我试图将最初使用EF4开发的项目迁移到EF6,以利用EF6事务管理. 我面临的问题是项目是使用Database First方法创建的,所以当我使用context.Database.UseTransaction等代码时,遇到以下错误:The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development.此异常在我的DbContext类的OnModelCreating方法内触发. 任何的想法 ? 谢谢 编辑: 问题...

c# – 如何在EF Core中放弃对上下文的更改【代码】

我有一个巨大的json格式的“扁平”对象列表,以及一个有点复杂的关系数据库模式(大约有20个表对应于展平对象).我正在尝试在新的关系数据库中自动插入那些展平的对象:foreach (var flattenedObject in flattenedObjects) {_repository.Insert(flattenedObject).Wait();//some time logging, etc }Insert()方法为不同表中的许多相关对象调用AddRangeAsync()和AddAsync(). 由于扁平化对象是遗留的,我会说它们中约有0.001%是格式错误并...

c# – 扩展Roles表后,实体类型IdentityRole不是当前上下文模型的一部分【代码】

我扩展了由Entity Framework创建的AspNetRoles,如下所示:public class AspNetRoles:IdentityRole {public AspNetRoles() : base() { }public String Label { get; set; }public String ApplicationId { get; set; }public AspNetApplications Application { get; set; }public static readonly String SystemAdministrator = "SystemAdministrator"; }我理解,因为我扩展了identityrole表,我不得不对我的用户管理器进行更改.这就是...

C#error1:当前上下文中不存在名称“DateTimeStyles”. error2:找不到类型或命名空间名称“CultureInfo”【代码】

嗨,我最好搜索谷歌,但无法从这些错误中恢复过来: “DateTimeStyles”名称在当前上下文中不存在 … 找不到类型或命名空间名称’CultureInfo(您是否缺少using指令或程序集引用?) ..如果我错过了什么,请你帮帮我..这是我的代码..using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Globalization; using System.Security.Permissions; using System.Threading;namespace Console...

C#动态getter和setter取决于应用程序上下文【代码】

我们有一个函数库,一些实用程序变量以两种不同的方式存储,具体取决于应用程序上下文桌面应用程序/网站 在网站中我们使用Sessions和桌面静态变量,我们希望联合并自动化这些变量的getter // setter而不会影响性能太多 例:public static class Cons {public static bool webMode; }public static class ConsWEB {public static string Username{get{ return HttpContext.Current.Session["username"].ToString();}set{ HttpContext.C...

c# – 异常消息是On数据上下文类型,有一个顶级的IQueryable属性,其元素类型不是实体类型【代码】

我建立了我在IIS 7中托管的WCFDataService,我将使用Reflection Provider作为数据源提供者.如果我将实体类型定义保存在我定义服务的同一个程序集中,我的示例工作,但如果我将实体类型移动到另一个引用的程序集,则不起作用有以下错误“server encountered an error processing the request. The exception message is ‘On data context type ‘EntityContainer’, there is a top IQueryable property ‘Cats’ whose element type i...

c# – Component.GetComponent()是一个方法,在给定的上下文中无效【代码】

如果游戏中发生了某些事情,我试图关闭一个实例化预制克隆的引力.我有这个:public class Controller : MonoBehaviour public Transform randomcoin;private void Start()if ( ... ) { randomcoin.GetComponent<Rigidbody>.useGravity = false; }这给了我这个错误:Component.GetComponent<T>() is a method, which is not valid in the given context有谁知道我怎么解决这个问题?解决方法:你在randomcoin.GetComponent< Rigidbo...

c# – 对象上下文,存储库和事务【代码】

我想知道在实体框架中使用转换的最佳方法是什么. 说我有三个存储库:Repo1(ObjectContext context)Repo2(ObjectContext context)Repo3(ObjectContext context)以及获取三个存储库的服务对象:Service(Repo1 repo1,Repo2 repo2, Repo3 repo3)Serive.CreateNewObject <- calls repo1, repo2, repo3 to do stuff.因此,当我创建服务时,我先创建三个存储库并将它们传递下来,每个存储库都会获取一个对象上下文,因此我的代码看起来像这样:...

c# – 无法创建对象上下文【代码】

在ASP.NET MVC中使用Entity框架时,我得到Unable来创建对象上下文错误. 背景 每次我向控制器发帖时,我都没有得到回复.我试着直接转到controller / Data / GetAll的方法,并收到此错误: 错误The specified named connection iseither not found in the configuration,not intended to be used with theEntityClient provider, or not valid.Description: An unhandled exceptionoccurred during the execution of thecurrent web req...

c# – 在UITypeEditor的EditValue中访问其他上下文数据【代码】

我正在调整一个WinForms应用程序.此应用程序具有包含PropertyGrid的窗体.将一个对象分配给SelectedObject属性,以便属性网格显示该对象的属性. 分配的对象类型具有一个属性,该属性带有指定UITypeEditor的EditorAttribute. UITypeEditor的这个实现在其GetEditStyle方法的重写中返回UITypeEditorEditStyle.Drop.它的EditValue方法显示一个ListBox,可以从中分配实例属性的值. 到目前为止一切顺利. 现在我有一个额外的要求,要求根据托管...

c# – 您可以使用导航栏切换上下文【代码】

我在ASP.net网站上工作,在我的一个表单中我添加了HTML控件,而从代码隐藏文件中使用该控件我得到了错误,我无法理解.<table style="width: 100%;" class="table-responsive"><tr><td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><input id="UserName" runat="server" type="text" class="form-control" placeholder="Username" required="required"/></td></tr><tr>codeBehind文件:protected void Page_Load(object s...

c# – 如何在不同的上下文中使用事务?【代码】

在我的应用程序中,我有这样的方法:public static bool DoLargeOperation() {bool res = true;res = res && DoFirstSubOperation();res = res && DoSecondSubOperation();res = res && DoThirdSubOperation();return res; }每个内部方法如下所示:public static bool DoFirstSubOperation() {using (var context = new EntityFrameworkContext()){// data modification.context.SaveChanges();} }例如,DoFirstSubOperation()和DoSe...

c# – 在代码的定时部分中防止上下文切换(或者测量然后减去在线程中实际没有花费的时间)【代码】

我有一个多线程应用程序,在某段代码中我使用秒表来测量操作的时间:MatchCollection matches = regex.Matches(text); //lazy evaluation Int32 matchCount; //inside this bracket program should not context switch {//start timerMyStopwatch matchDuration = MyStopwatch.StartNew();//actually evaluate regexmatchCount = matches.Count;//adds the time regex took to a listdurations.AddDuration(matchDuration.Stop()); ...

c# – 使用类名查询上下文仅在运行时知道【代码】

我正在寻找创建一段代码,以允许我根据字符串类名称动态查询我的数据库. 我想要的简要概述: 我的背景:public class MyContext : DbContext {public DbSet<Foo> Foos {get;set;}public DbSet<Bar> Bars {get;set;} }有了我的设置,我通过做基本的context.Foos.Where(…)查询这个上下文,我基本上也想做同样的事情,但不必在编译时知道.Foos部分,喜欢它在运行时完成. 逻辑上我想要的是:var results = context."ClassName".Where(...)我...

c# – 当前上下文中不存在名称“DefaultAuthenticationTypes”【代码】

我正在尝试在我的Web应用程序中实现基于角色的授权,如下所示:[HttpPost] [ActionName("Login")] public ActionResult Login(LoginViewModel model) {if (ModelState.IsValid){string userName = model.Username;string[] userRoles = (string[])Session["UserRoles"];ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userN...