草庐IT

content_type_task

全部标签

c# - Code First 迁移种子错误 : The binary operator Equal is not defined for the types 'System.Nullable` 1[System. Int32 ]' and ' System.Int32'

在我的数据库中播种时,我的更新标识符出现以下问题:context.ClientPromos.AddOrUpdate(cp=>new{cp.ClientID,cp.Recommendation_ID,cp.PromoCode_ID},newClientPromo{ClientID=0,Recommendation_ID=Rec30Off.RecommendationID,PromoCode_ID=pc30PerOffProd.PromoCodeID},newClientPromo{ClientID=0,Recommendation_ID=RecKnow.RecommendationID,

c# - HttpRequest.Content.IsMimeMultipartContent() 在应该返回 true 时返回 false

我需要将HTTP请求作为MultiPartFormData发送到RESTController。它正在工作,但现在我对我的Controller进行的检查声称请求的类型不正确,即使我可以在调试器中看到请求的类型正确。供引用:这是调用它的控制台应用程序代码:usingSystem;usingSystem.IO;usingSystem.Net.Http;usingSystem.Net.Http.Headers;usingSystem.Text;namespaceQuickUploadTestHarness{classProgram{staticvoidMain(string[]args){us

c# - Mono.Cecil type.IsAssignableFrom(derivedType) 等效项

我正在使用Mono.Cecil在Assembly中查找派生自给定的类型。通常可以使用IsAssignableFrom()方法来完成,但我无法确定它在Cecil中是等效的。有没有这样的方法或其他方法来检查它?谢谢迈克 最佳答案 继承检查和“赋值兼容性”检查实际上是不同的东西。您要检查继承还是“分配兼容性”?赋值兼容性包括很多东西,包括有符号/无符号转换、枚举到基类型的转换、char至short转换、通用方差转换、从接口(interface)到object的转换,从数组到IList和IList以及它们的基本接口(interface)、数

c# - Web Api 请求抛出 "Error while copying content to a stream."

我正在尝试实现这个codeexample,但得到一个HttpRequestException-“将内容复制到流时出错。”当调用ReadAsStringAsync()方法时。内部异常是“无法访问已处置的对象”。我正在使用Fiddler来发出请求。我不明白。有人可以解释为什么我会收到此异常并提供解决方案吗?网络API方法:publicasyncTaskPost(HttpRequestMessagerequest){try{varjsonString=awaitrequest.Content.ReadAsStringAsync();}catch(Exceptionex){throw;}ret

c# - List<Task> - 使用 C# Entity Framework 的 UPSERT 数据库记录

我有一个Employee对象,我正在尝试使用单个DB实体上下文使用多个任务(并行执行)来更新记录(即更新/删除)。但是我收到以下异常Message="Objectreferencenotsettoaninstanceofanobject."考虑以下DTOpublicclassEmployee{publicintEmployeeId{get;set;}publicstringFirstName{get;set;}publicstringLastName{get;set;}publicListContactPhoneNumbers{get;set;}publicListContactEma

c# - Linq 和相等运算符 : Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object'

我试图重写C#中的相等(==)运算符来处理任何类型与自定义类型的比较(自定义类型实际上是null周围的包装器/框)。所以我有这个:internalsealedclassNothing{publicoverrideboolEquals(objectobj){if(obj==null||objisNothing)returntrue;elsereturnfalse;}publicstaticbooloperator==(objectx,Nothingy){if((x==null||xisNothing)&&(y==null||yisNothing))returntrue;returnfal

c# - EF6 : Code First Complex Type

我无法让EntityFramework将具有值对象(复杂类型)字段的域实体类展平到一个表中。如果我告诉我的模型构建器忽略我的值对象/复杂类型,一切正常,但这会导致我的表中丢失值对象的所有属性。一旦删除忽略语句,我就会得到“在多个位置创建跨实体共享的值”。如果我查看生成的CESQL文件,我会看到一个额外的表,该表以我的域类命名并附加了1,并且仅包含值对象参数。一些代码:我的领域类:publicUser{privateUser(){}publiclongId{get;privateset;}//dontask,inheritedlegacydatabasepublicstringUserI

c# - Async/Await VS Task.Run : When to use ? 如何使用?

好吧,我希望我掌握了async/await的基础知识,但仍有一些问题在我脑海中挥之不去。但是现在我说的就是这个问题了。假设在这个简单的例子中staticvoidMain(string[]args){Method();Console.WriteLine("MainThread");Console.ReadLine();}publicasyncstaticvoidMethod(){awaitTask.Run(newAction(LongTask));Console.WriteLine("NewThread");}publicstaticvoidLongTask(){Thread.Sleep

c# - 设置 "Always copy to output directory"时,Content 和 None 有什么区别?

在csproj文件中,我们可以使用None或Content元素包含一个文件。来自MSDN,它说:None-Thefileisnotincludedintheprojectoutputgroupandisnotcompiledinthebuildprocess.Anexampleisatextfilethatcontainsdocumentation,suchasaReadmefile.Content-Thefileisnotcompiled,butisincludedintheContentoutputgroup.Forexample,thissettingisthedefaultva

c# - 为什么 Task.ContinueWith 在此单元测试中执行失败?

我遇到了一个单元测试失败的问题,因为TPL任务从未执行过它的ContinueWith(x,TaskScheduler.FromCurrentSynchronizationContext())。问题原来是因为在任务启动之前不小心创建了一个WinformsUI控件。这是一个重现它的例子。您会看到,如果您按原样运行测试,它就会通过。如果您在未注释Form行的情况下运行测试,它将失败。[TestClass]publicclassUnitTest1{[TestMethod]publicvoidTestMethod1(){//CreatenewsynccontextforunittestSynch