草庐IT

useful-code-snippets-to-develop-i

全部标签

c# - LINQ to Entities 查询不支持转换为十进制

我有一个数据库表Transaction(transactionID,LocalAmount...)。其中Localamount属性的数据类型是float。在UI上,我试图在按钮单击事件的一行中返回列(Localamount)的SUM。我使用了decimal而不是float但是,我在转换为decimal的代码中遇到错误System.NotSupportedExceptionwasunhandledbyusercodeMessage=CastingtoDecimalisnotsupportedinLINQtoEntitiesqueries,becausetherequiredprecisi

c# - JWT 错误 IDX10634 : Unable to create the SignatureProvider C#

我正在尝试运行我的应用程序,但它因以下错误而卡住:System.NotSupportedExceptionHResult=0x80131515Message=IDX10634:UnabletocreatetheSignatureProvider.Algorithm:'[PIIishiddenbydefault.Setthe'ShowPII'flaginIdentityModelEventSource.cstotruetorevealit.]',SecurityKey:'[PIIishiddenbydefault.Setthe'ShowPII'flaginIdentityModelEve

c# - 如何使用 Simple injector、Repository 和 Context - code first

我正在尝试使用SimpleInjector创建我的存储库并在业务逻辑层中使用它(我也想使用PerWebRequest方法)。在DAL层我有:publicinterfaceIRepositorywhereT:class{voidAdd(Tentity);voidDelete(Tentity);voidDelete(intid);voidUpdate(Tentity);TGetById(intId);IQueryableAll();IEnumerableFind(Funcpredicate);}和:publicclassEFRepository:IRepository,IDisposabl

c# - "unexpected response code for operation : 1"是什么意思?

我从尝试在Azure表存储中插入记录的应用程序中收到“意外的操作响应代码:1”。基本上是将数据放在TableOperation中,并且已经按100行block对插入进行了批处理。在网络上真的找不到很多关于此Azure错误消息中特定“1”代码的信息。 最佳答案 当批处理操作失败时,表服务返回HTTP状态代码400,同时发送导致该批处理失败的实体的索引。"unexpectedresponsecodeforoperation:1"这意味着在批处理中的位置1处插入实体时出现错误。 关于c#-"u

c# - Visual Studio 2015 中是否有用于 C# 的 "Go To Variable Type Declaration"函数或一个免费插件?

voidMagicalFunction(MagicalTypemagic){...magic.Poof("something");...varfoo=magic.GetFoo();...}在变量magic上按下热键将导航到类型MagicalType的定义。在foo上按下热键将转到类型Foo的定义,由于类型推断,它在这里不直接可见。Resharper插件具有此功能(称为GoToTypeofSymbol),但是是否有内置的替代方案或免费扩展来执行此操作? 最佳答案 右键单击“var”关键字,从上下文菜单中选择“Gotodefinitio

c# - 在 Linq-To-Sql 中避免 "Nullable object must have a value."

我有一个这样的方法查询:publicIListGetBusinessObject(Guid?filterId){using(vardb=newL2SDataContext()){varresult=fromboindb.BusinessObjectswhere(filterId.HasValue)?bo.Filter==filterId.value:trueorderbybo.NameselectSqlModelConverters.ConvertBusinessObject(bo);returnresult.ToList();}}在运行时,这会抛出一个System.InvalidOp

c# - Entity Framework Code First 中的有效原始属性是什么?

当我尝试将列映射到我的模型类中的char数据类型时,出现错误:Theproperty'[ColumnName]'isnotadeclaredpropertyontype'[ClassName]'.VerifythatthepropertyhasnotbeenexplicitlyexcludedfromthemodelbyusingtheIgnoremethodorNotMappedAttributedataannotation.Makesurethatitisavalidprimitiveproperty.EFCodeFirst的有效基元类型是什么? 最佳答

c# - 是否有必要将 usings 与 IDisposable 对象嵌套在一起?

我是否必须将所有IDisposable对象包装在using(){}语句中,即使我只是将一个对象传递给另一个对象?例如,在下面的方法中:publicstaticstringReadResponse(HttpWebResponseresponse){stringresp=null;using(StreamresponseStream=response.GetResponseStream()){using(StreamReaderresponseReader=newStreamReader(responseStream)){resp=responseReader.ReadToEnd();}}

c# - 将 using 语句放入命名空间失败

我正在尝试使用stylecop正确设置一些旧代码的样式。它要求将using语句放入其中。有效除了一个人以外,所有人都很好。我已将问题简化为以下代码。namespaceB.C{usingSystem;publicclassHidden{publicvoidSayHello(){Console.WriteLine("Hello");}}}namespaceA.B.C{usingB.C;publicclassProgram{staticvoidMain(string[]args){newHidden().SayHello();}}}这给出了编译错误Error"Thetypeornamespa

c# - 是否可以将反射与 linq to entity 一起使用?

我试图通过创建一个扩展方法来一般地处理过滤来稍微清理我的代码。这是我要清理的代码。varqueryResult=(fromrindc.Retailersselectr);if(!string.IsNullOrEmpty(firstName))queryResult=queryResult.Where(ex=>SqlFunctions.PatIndex(firstName.Trim(),ex.FirstName.Trim())>0);if(!string.IsNullOrEmpty(lastName))queryResult=queryResult.Where(ex=>SqlFuncti