在EF Code First中过滤导航属性

我在EF中使用Code First。 假设我有两个实体: public class Farm { …. public virtual ICollection Fruits {get; set;} } public class Fruit { … } 我的DbContext是这样的: public class MyDbContext : DbSet { …. private DbSet FarmSet{get; set;} public IQueryable Farms { get { return (from farm in FarmSet where farm.owner == myowner select farm); } } } 我这样做,以便每个用户只能看到他的农场,我不必调用每个查询的位置到数据库。 现在,我想过滤掉一个农场的所有水果,我尝试了这个(在Farm类中): […]

SQLite更新后:无法在DLL“SQLite.Interop.dll”中找到名为“sqlite3_changes_interop”的入口点

我的C#/ SQLite工作正常,直到我决定更新SQLite DLL(从1.0.82.0到1.0.84.0)。 现在我遇到了这个崩溃: 无法在DLL“SQLite.Interop.dll”中找到名为“sqlite3_changes_interop”的入口点 A first chance exception of type ‘System.EntryPointNotFoundException’ occurred in System.Data.SQLite.dll System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionSparkleShare.vshost.exeSystem.EntryPointNotFoundException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Unable to find an entry point named ‘sqlite3_changes_interop’ in DLL ‘SQLite.Interop.dll’. at System.Data.SQLite.UnsafeNativeMethods.sqlite3_changes_interop(IntPtr db) at System.Data.SQLite.SQLite3.get_Changes() at System.Data.SQLite.SQLiteStatement.TryGetChanges(Int32& changes) at System.Data.SQLite.SQLiteDataReader.NextResult() at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() […]

打开SQL连接时出现算术溢出exception

打开与底层SQL数据库的SQL连接时,我得到了非常奇怪的ArithmeticOverflowException (下面包含堆栈跟踪)。 使用哪个版本的服务器并没有什么区别(我已经validation了MS SQL 2005/2008/2012/2014),错误仍然是相同的。 安装了Windows Update的所有最新更新和修补程序。 操作系统是Windows 8.1 / 10(两个系统都相同)。 服务器在本地安装,并通过用户和密码建立连接。 连接超时validation范围为15到1000秒。 最令人惊讶的是应用程序工作正常,并与服务器正常通信,执行许多不同的查询,但突然发生此exception。 我注意到这个exception在一些Windows更新后开始出现(不知道哪一个)。 我查看了.NET代码,但不知道是什么原因导致算术溢出exception…… – 堆栈跟踪 – in SNIOpenSyncExWrapper(SNI_CLIENT_CONSUMER_INFO* , SNI_ConnWrapper** ) in SNINativeMethodWrapper.SNIOpenSyncEx(ConsumerInfo consumerInfo, String constring, IntPtr& pConn, Byte[] spnBuffer, Byte[] instanceName, Boolean fOverrideCache, Boolean fSync, Int32 timeout, Boolean fParallel) in System.Data.SqlClient.SNIHandle..ctor(ConsumerInfo myInfo, String serverName, Byte[] spnBuffer, Boolean ignoreSniOpenTimeout, Int32 timeout, Byte[]& […]

替代使用InStr

我怎么能使用不同的function“InStr”这是我正在使用的代码并且工作正常但是离开InStr是我的目标 i = InStr(1, Hostname, Environment.Newline)

c#中类的内存对齐?

(顺便说一句。这是指32位操作系统) 一些更新: 这绝对是一个对齐问题 有时对齐(无论出于何种原因?)是如此糟糕,以至于对双倍的访问速度比其最快访问速度慢50倍。 在64位计算机上运行代码减少了问题,但我认为它仍然在两个时间之间交替(我可以通过将双倍更改为32位机器上的浮点数来获得类似结果) 在mono下运行代码没有问题 – 微软,你有没有机会从那些Novell家伙那里复制一些东西? 有没有办法在c#中记忆对齐类的分配? 以下演示(我认为!)没有正确对齐的双重错误。 它对存储在类中的double执行一些简单的数学运算,对每次运行进行计时,在变量上运行5次定时运行,然后再分配一个新变量并重新执行。 基本上结果看起来你要么具有快速,中速或慢速记忆位置(在我的古代处理器上,这些最终每次运行大约40,80或120ms) 我曾尝试过使用StructLayoutAttribute,但没有任何乐趣 – 也许其他事情正在发生? class Sample { class Variable { public double Value; } static void Main() { const int COUNT = 10000000; while (true) { var x = new Variable(); for (int inner = 0; inner < 5; ++inner) { // move allocation […]

如何在C#中使用RegisterHotKey()?

我正在尝试注册一个热键,我正在翻译这个 C ++代码,我写道: using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport(“user32.dll”)] public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, int vk); [DllImport(“user32”)] public static extern bool GetMessage(ref Message lpMsg, IntPtr handle, uint mMsgFilterInMain, uint mMsgFilterMax); public const int MOD_ALT = 0x0001; public const int MOD_CONTROL = […]

检查是否可以访问URL – 帮助优化类

net 4和c#。 如果Uri(字符串)返回HTTP状态代码200,我需要一个能够返回Bool值的Class。 目前我有这个代码(它使用try来查看是否可以连接到Uri),但我希望用“HttpStatusCode.OK”实现。 你知道更好的方法吗? 谢谢。 public static bool IsReachableUri(string uriInput) { // Variable to Return bool testStatus; // Create a request for the URL. WebRequest request = WebRequest.Create(uriInput); request.Timeout = 15000; // 15 Sec WebResponse response; try { response = request.GetResponse(); testStatus = true; // Uri does exist response.Close(); } catch (Exception) { testStatus […]

如何使用带有XDocument的构造函数将XML反序列化为对象?

我上课了: public class MyClass { public MyClass(){} } 我希望能够使用XMLSeralizer直接在构造函数中反序列化XDocument: public class MyClass { private XmlSerializer _s = new XmlSerializer(typeof(MyClass)); public MyClass(){} public MyClass(XDocument xd) { this = (MyClass)_s.Deserialize(xd.CreateReader()); } } 除了我不允许在构造函数中指定“this”。 这可能吗?

属性或索引器’string.this ‘不能分配给 – 它是只读的

我没有遇到问题 – 我试图做一个简单的动作: for(i = x.Length-1, j = 0 ; i >= 0 ; i–, j++) { backx[j] = x[i]; } 两者都宣布: String x; String backx; 问题是什么 ? 它说标题中的错误……如果有问题 – 还有另一种方法吗? 结果(名称为’backx’提示)是backx将向后包含字符串X. PS x不为空 – 它包含来自另一个字符串的子字符串。

如何防止C#编译器/ CLR在DEBUG构建中优化掉未使用的变量?

在调试时我试图将计算的中间结果保存到变量中,以便在满足断点条件时我可以检查该值。 但是,C#编译器(或CLR)将该变量优化为未使用。 我通过使变量成为类的公共字段来解决问题,但是我想知道是否有一个直接的解决方案来解决这个问题。 未选中“优化代码”复选框。 构建配置是Debug。 编辑:发现它只影响迭代器中一些未使用的变量,这些变量通常最终会作为自动生成的迭代器类中的字段; 保留在不包含yield语句的块中作用域的未使用变量。