草庐IT

c# - EF 5 代码迁移错误 : "There is already an object named _____ in the database"

在进行EF5代码迁移时遇到了一个反复出现的奇怪问题,现在让我无法工作。尝试运行update-database并收到此错误:Thereisalreadyanobjectnamed'RequestStatus'inthedatabase.详细的日志转储:PM>update-database-vUsingStartUpproject'LicensingWorkflow'.UsingNuGetproject'LicensingWorkflow'.Specifythe'-Verbose'flagtoviewtheSQLstatementsbeingappliedtothetargetdataba

c# - LinqToSQL 错误 : Operation is not valid due to the current state of the object

在更新命令期间,我收到以下错误:Operationisnotvalidduetothecurrentstateoftheobject我试图从更新命令中删除一列并且它工作正常。此列是一个FK,与其他工作正常的FK相似。这是执行更新的代码:ti.NumeroTitolo=titolo.Numero;ti.RKTipoTitoloGenereTitolo=titolo.RkTipoTitoloGenereTitolo;ti.RKBanca=titolo.RkBanca;ti.DataScadenza=titolo.DataScadenza;ti.RKTipoEsito=titolo.RkTi

c# - Entity Framework 6 : Adding child object to parent's list vs. 将子项的导航属性设置为父项

我有一个现有数据库,其中包含两个表MailServers和MailDomains。MailDomains的外键列MailServerId指向MailServers中的Id主键列。所以我们这里是一对多的关系。我关注了thisarticle并通过实体数据模型向导中的“代码优先从数据库”模型创建了我的EntityFrameworkPOCO。这产生了以下两个C#类:publicpartialclassMailServer{publicMailServer(){MailDomains=newHashSet();}publicintId{get;set;}publicvirtualICollect

c# - "Unable to cast object of type ' System.Net.Http.Formatting.JsonContractResolver ' to type ' Newtonsoft.Json.Serialization.DefaultContractResolver '."

我们有一个最近被转移到新服务器的WEBAPI项目。在对项目的有效负载进行一些添加后,我正在运行我的项目,但它突然抛出以下错误:Unabletocastobjectoftype'System.Net.Http.Formatting.JsonContractResolver'totype'Newtonsoft.Json.Serialization.DefaultContractResolver'.有问题的代码行在global.asax中:protectedvoidApplication_Start(){GlobalConfiguration.Configure(WebApiConfig.R

c# - 在 Protobuf.NET 中序列化 List<object> (其中对象支持原语)?

如何使用protobuf-net序列化这样的对象:publicclassMyObject{publicstringKey{get;set;}publicListValues{get;set;}}当我尝试使用TypeModelprotobuf-net对此进行序列化时,抛出一个错误,指出它不知道如何序列化System.Object。现在我知道Values只会包含基元(int、string、float、DateTime等)。那么如何让protobuf-net知道这一点呢? 最佳答案 在任何意义上,这在纯ProtoBuf中都是不可行的。Pr

c# - SOAP 错误 : "Server was unable to process request" "Object reference not set to an instance of an object"

当我向本地IIS中的服务发送SOAP请求时,一切正常。当我向在另一台主机上的IIS上运行的同一服务发送SOAP请求时,一切正常。但是当另一个程序员向我的服务发送SOAP请求时,他通常会得到正确的响应,除了返回服务中的一个方法:soap:ServerServerwasunabletoprocessrequest.--->Objectreferencenotsettoaninstanceofanobject.我需要了解他收到此错误的原因。他的SOAP请求与SOAP请求完全相同,但我的有效,而他的无效。 最佳答案 如果您不确切知道错

c# - 枚举 MatchCollection 时,为什么 var 结果是 Object 类型而不是 Match 类型?

我注意到下面的代码有些奇怪:MatchCollectionmc=Regex.Matches(myString,myPattern);foreach(varmatchinmc)Console.WriteLine(match.Captures[0]);//变量match的类型是Object而不是Match。我习惯于使用var枚举集合,没有这样的问题。为什么MatchCollection不同? 最佳答案 MatchCollection是在.NET2之前编写的,所以它只是实现了IEnumerable而不是IEnumerable.但是,您可以

c# - 如何使用 Linq to object 构建层次结构?

我有一个数据结构列表:publicListPersonals(){returnnewList{newPersonal{Id=0,Name="Name0"},newPersonal{Id=1,Name="Name1",ParentId=0},newPersonal{Id=2,Name="Name2",ParentId=0},newPersonal{Id=3,Name="Name3",ParentId=0},newPersonal{Id=4,Name="Name4",ParentId=1},newPersonal{Id=5,Name="Name5",ParentId=1},newPerso

c# - 检查 Object 在每个属性中是否为 null

我有多个属性的类;publicclassEmployee{publicstringTYPE{get;set;}publicint?SOURCE_ID{get;set;}publicstringFIRST_NAME{get;set;}publicstringLAST_NAME{get;set;}publicListdepartmentList{get;set;}publicListaddressList{get;set;}}有时这个对象返回给我任何属性的值Employeeemp=newEmployee();emp.FIRST_NAME='abc';其余值为空。这个可以但是,如何检查对象属

c# - 从 Expression<Func<T, object>> 实例获取实际返回类型

我有一个接受Expression>的方法实例。我想获取特定表达式实例返回的实际数据类型,而不是object.我可以让它为直接属性引用工作,所以如果我传入表达式x=>x.IntegerProperty我可以获得整数的类型引用。此方法需要将其转换为MemberExpression。但是,我无法让它适用于任意表达式。例如,如果表达式是x=>x.IntegerProperty.ToString()我想获取字符串的类型引用。我无法将其编译为MemberExpression,如果我只是.Compile()它并检查我得到“对象”的返回类型。如何查看具体的表达式实例并推导出实际的返回类型?