草庐IT

non-primary

全部标签

c# - Entity Framework 代码第一个链接表中违反 PRIMARY KEY 约束

我有一个用户表和一个角色表。有一个自动生成的UsersRoles链接表,其中包含来自User和Roles表的Id。这是使用以下代码生成的:modelBuilder.Entity().HasMany(u=>u.Roles).WithMany(r=>r.Users).Map(c=>{c.MapLeftKey("UserId");c.MapRightKey("RoleId");c.ToTable("UsersRoles");});当我尝试添加不相关的实体并调用Context.SaveChanges()时,我收到以下错误:ViolationofPRIMARYKEYconstraint'PK_U

Mysql出现问题:ERROR 1062 (23000): Duplicate entry ‘‘ for key ‘PRIMARY‘解决方案

回城传送–》《数据库问题解决方案》❤️作者主页:小虚竹❤️作者简介:大家好,我是小虚竹。Java领域优质创作者?,CSDN博客专家?,华为云享专家?,掘金年度人气作者?,阿里云专家博主?,51CTO专家博主?❤️技术活,该赏❤️点赞?收藏⭐再看,养成习惯PC端左侧加我微信(文末名片添加也行),进社群,有送书等更多活动!问题ERROR1062(23000):Duplicateentry‘’forkey‘PRIMARY’解决方案这个错误通常是因为在插入数据时,数据表的主键列存在重复值。解决方案如下:1.检查数据表主键列的值:查看数据表中主键列的值,看是否存在重复值。2.删除重复的数据:删除数据表中

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

c# - Entity Framework 4 : How to find the primary key?

我正在尝试使用EF4创建一个通用方法来查找对象的主键。例子publicstringGetPrimaryKey(){...}为了提供更多信息,我正在使用TekpubStarterKit,下面是我正在尝试启动和运行的类(class)usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Data.Objects;usingSystem.Data.Objects.ELinq;usingSystem.Data.Linq;usingWeb.Infrastructure.Sto

c# - Entity Framework : Alternate solution to using non primary unique keys in an association

我知道EntityFramework不允许您使用非主唯一键作为外键关联从数据库生成模型。我可以手动修改EDMX吗?如果是这样,有人可以给我一个例子或引用吗?如果不是,还有其他可能吗?最简单的例子:这是表的DDL。您会注意到我有一个从PersonType.TypeCode到Person.TypeCode的外键CREATETABLE[dbo].[PersonType]([PersonTypeId][int]NOTNULL,[TypeCode][varchar](10)NOTNULL,[TypeDesc][varchar](max)NULL,CONSTRAINT[PK_PersonType]

c# - 低级差异 : non-static class with static method vs. 静态类与静态方法

我想知道使用具有静态方法的非静态类与具有相同静态方法的静态类的一般好处(或缺点)是什么,除了我不能使用非静态类中的静态方法作为扩展方法。例如:classNonStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromanon-staticclass.";}}与此相比:staticclassStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromastaticclass.";}}使用一种方法优于另一种方法对性能/内存有何影响?注意:假设我不需要

c# - 林克 : Delete and Insert same Primary Key values within TransactionScope

我想在一个事务中用新记录替换数据库中的现有记录。使用TransactionScope,我有using(varscope=newTransactionScope()){db.Tasks.DeleteAllOnSubmit(oldTasks);db.Tasks.SubmitChanges();db.Tasks.InsertAllOnSubmit(newTasks);db.Tasks.SubmitChanges();scope.Complete();}我的程序抛出System.InvalidOperationException:Cannotaddanentitythatalreadyexis