Tag: .net

使用LINQ处理大型SQL查询

我试图通过实体数据模型从MS SQL数据库中的表中获取大约2000万条目的每条记录。 我最初的想法是以块的forms检索数据,如下所示: public IEnumerable<IEnumerable> GetDevicesInChunks(int chunkSize) { using (var db = new AccountsEntities()) { for (int i = 0; i < db.devices.Count(); i += chunkSize) { yield return db.devices.Skip(i).Take(chunkSize); } } } 但是,看来我必须在调用Skip之前调用OrderBy ,从我使用上述方法时抛出的exception来判断 The method ‘Skip’ is only supported for sorted input in LINQ to Entities. The method ‘OrderBy’ must be called before […]

如何在RDLC中设置参数值

我在报告中为日期范围添加了两个文本框。 要填充文本框中的值,我将参数设置为文本框。 现在,日期范围来自名为DateRange的表单,该表单具有两个DateTimePickers。 如何设置rdlc中的文本框的值等于这些DataTimePickers?

注入的依赖项是公共可访问还是私有?

是否应将依赖项存储到具有私有setter和public getter的私有字段或属性? 这适用于构造函数DI。 为了清楚起见,在属性示例中,我不希望将这些添加到附带的接口,除非它有意义 – 即它们只在实现类型中可见: interface IFoo { void DoSomething(); } class Foo : IFoo { private readonly IService dependency; public Foo(IService dependency) { this.dependency = dependency; } } class Bar : IFoo { public Foo(IService dependency) { this.Dependency = dependency; } public IService Dependency { get; private set; } }

entity framework4和同义词

如果在数据库A中存在名为“MyTable”的表,该表实际上来自指向另一个数据库(B)的同义词,我是否可以将该表创建为表示数据库A的entity framework模型中的实体,因为它实际上存在在另一个数据库? 我很好奇,如果EF 4的情况有所改善,那么: http : //social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/fff1067a-650d-4b47-a4e8-79eedebe5c11/ 谢谢。

如何使用reflection将新项添加到集合中

我正在尝试使用reflection将未知对象添加到未知集合类型,并且当我实际执行“添加”时,我遇到exception。 我想知道是否有人可以指出我做错了什么或另类? 我的基本方法是迭代通过reflection检索的IEnumerable,然后将新项添加到第二个集合中,我稍后可以将其用作替换集合(包含一些更新的值): IEnumerable businessObjectCollection = businessObject as IEnumerable; Type customList = typeof(List) .MakeGenericType(businessObjectCollection.GetType()); var newCollection = (System.Collections.IList) Activator.CreateInstance(customList); foreach (EntityBase entity in businessObjectCollection) { // This is the area where the code is causing an exception newCollection.GetType().GetMethod(“Add”) .Invoke(newCollection, new object[] { entity }); } 例外是: “Eclipsys.Enterprise.Entities.Registration.VisitLite”类型的对象无法转换为“System.Collections.Generic.List`1 [Eclipsys.Enterprise.Entities.Registration.VisitLite]”类型。 如果我使用这行代码代替Add() ,我得到一个不同的exception: newCollection.Add(entity); 例外是: 值“”不是“System.Collections.Generic.List`1 [Eclipsys.Enterprise.Entities.Registration.VisitLite]”类型,并且不能在此通用集合中使用。

在完整的.NET框架上测试Asp.Net Core

我想对一个针对完整的.net框架的asp.net核心项目进行unit testing。 我尝试使用本博文中概述的“普通”unit testing项目模板和.net核心项目,但两次尝试均失败,因为我的Web项目的程序集无法在任何一个测试项目中引用。 有没有办法在完整框架上unit testingasp.net核心应用程序?

MessageReceiver.ReceiveBatch()未按预期工作

我试图使用MessageReceiver中的ReceiveBatch方法从ServiceBus批量接收消息: IEnumerable messages; var messagingfactory = MessagingFactory.CreateFromConnectionString(“ConnectionString”); var msgrcvr = messagingfactory.CreateMessageReceiver(“queueName”, ReceiveMode.ReceiveAndDelete); messages = msgrcvr.ReceiveBatch(20, timeoutInSecs); 我已经使用Service Bus Explorer检查了我的队列包含20条消息。 此代码仅在消息结构中返回一条消息。 我遗失了一些财产吗?

C#xml序列化

我在c#中将对象序列化为xml,我想序列化 public String Marker { get; set; } 成 当字符串标记没有值时。 现在我明白了 for Marker == string.Empty ,没有标记节点为null 。 我怎么能得到这个?

处理BigInteger问题

假设以下Diffie-Hellman信息也可以在此页面上找到 1)p string givenp = “00e655cc9e04f3bebae76ecca77143ef5c4451876615a9f8b4f712b8f3bdf47ee7f717c09bb5b2b66450831367d9dcf85f9f0528bcd5318fb1dab2f23ce77c48b6b7381eed13e80a14cca6b30b5e37ffe53db15e2d6b727a2efcee51893678d50e9a89166a359e574c4c3ca5e59fae79924fe6f186b36a2ebde9bf09fe4de50453”; BigInteger p = new BigInteger(HexToBytesv2(givenp)); 2)G BigInteger g = new BigInteger(2); 3)商家私钥 string merchantPrivateKeyHEX = “48887dfd090d175e33beea29e7b38334299289069f9ab492b67807905faa98d96d22d79205bef03f14af093f1797b904734132c34a388fdc79e20497bfa1465fec2aac4fabdf3bb0c9be8685d20f7bfe0346a9abdf7fa89838c3fa9ca6abdb70bea66795ab6699cc154db59490e4159f142f7bddff603c1d3d6c4fff8177e11d”; BigInteger a = new BigInteger(HexToBytesv2(merchantPrivateKeyHEX)); 使用公式publickey = g ^ a mod p我应该获得初始链接中提供的公钥,但是在执行时 BigInteger A = BigInteger.ModPow(g, a, p); ToHex(A.ToByteArray()) 我得到的结果是 00f85c41e84446ecfe43c9911df31d3cf60d83642afd496b741363290139badf75f8b8c5c010dda2446dd483dc553b6c2698c16c9d082391677785f81d54bc9c7c45f8b6d5bdb3e49fec7f5522b880c8c753fb7d3ff2c81e47dcb27d52842def40a812dc95cc679575baf237a955ee9944bd0797326f2a0a58c6c087f9b0b9e82c 代替 00d9abd78c93dfddeb920d57d6513126d8f1118c9237a45101408dbffe6cfd95b011a016e4e0ab8aef0601e836a452b8bb88be7ca71e4f22f97aa65f8358ee69348d1227d65db6e53641d1a6542aa4be4b4adc75fac816af79a8e3f5097f8313e7b725df37eadc8c774e2033dfa99c95ccef333bf402b066198c30481e2a83875c 有任何想法吗? 我一定很遗憾,但我不确定那可能是什么。 PS添加正在使用的function: public static byte[] HexToBytesv2(this string hex) { […]

特定于环境的StructureMap配置?

回到我使用StructureMap 2.6时,我能够通过将PullConfigurationFromAppConfig设置为TRUE来从配置中提取配置数据。 这有助于我根据构建配置覆盖实例。 在最新版本中,这似乎已不复存在。 如何通过配置文件指定自定义实例,特别是web.config (我目前正在根据构建配置进行转换)。 这可能吗? 还有另一个支持这个的IoC框架吗? 谢谢。