使用Entity Framework的StructuralTypeConfiguration.Ignore()忽略除指定集之外的所有属性

在EF CodeFirst Fluent API中,我可以这样编写: modelBuilder.Entity() .Ignore(e => e.Property1); modelBuilder.Entity() .Ignore(e => e.Property2); 如何忽略所有的属性,但一小部分,如下: modelBuilder.Entity() .IgnoreAllBut(e => e.ID, e => e.Important); 是否可以编写像这样的IgnoreAllBut扩展方法?

SQL Server CLR UDF Parallelism redux

我一直在研究SQL Server CLR UDF和并行性。 普遍的共识似乎是在SQL Server 2008及更高版本中,带有DataAccessKind.None的标量值CLR UDF应该允许并行执行。 但是,当我在SQL Server 2012的视图中使用我的标量值UDF时,它仍然会杀死连接中的并行执行等。 有什么特别的东西需要添加到我的C#代码或T-SQL UDF定义中,以表明它对于并行执行是安全的吗? 谢谢。

在c#中记录按键时输入特殊字符时显示的双字符

我有一个应用程序记录用户按下的任何内容,但是当我按下特殊字符时,例如´ with a , ´´a ,to ´´a ; 同样的事情,当我想得到à ,然后我得到“a ,所以所有特殊字符输入两次然后常规字符输入后。 我一直在搜索,真的找不到任何东西。 但我注意到问题出在ToAscii方法中,没有正确输入字符。 public string GetString(IntPtr lParam, int vCode) { try { bool shift = Keys.Shift == Control.ModifierKeys || Console.CapsLock; string value = “”; KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure( lParam, typeof(KeyboardHookStruct)); byte[] keyState = new byte[256]; byte[] inBuffer = new byte[2]; DllClass.GetKeyboardState(keyState); var ascii= DllClass.ToAscii( MyKeyboardHookStruct.vkCode, […]

建议设计:应用程序中几乎每个对象都有loggger

我正在写一个应用程序。 我使用NLog进行日志记录。 在这个应用程序中几乎每个对象都可以写入日志。 我为此定义了受保护的成员: protected Logger logger; protected virtual Logger Logger { get { return logger ?? (logger = LogManager.GetLogger(this.GetType().ToString())); } } 在这种情况下,我需要为应用程序中的每个基类复制/粘贴此代码。 或者我看到其他选项:使用记录器定义特定于应用程序的根对象并将其子类化。 但在语义上这听起来是错误的,因为对我来说这不是真正的“是 – ”的情况。 有没有更好的选择?

Windows窗体中的打印面板C#

我有一个情况。 我需要在Visual Studio 2010中使用C#以Windows窗体创建员工卡结构。该结构可能包含带有白色背景的标签和图片框。 我没有问题创建它,但我也在这个窗体上给出一个名为“打印”的按钮,以便用户可以打印该卡。 我搜索了它,但没有找到具体的东西。 请帮帮我。 namespace Employee_Card_Manager { public partial class Card : Form { public Card(String a, String b, String c, String d, String e, String f, String g, String h, String i) { InitializeComponent(); this.label2.Text = a; this.label9.Text = b; this.label10.Text = c; this.label11.Text = d; this.label12.Text = e; this.label13.Text = […]

在C#中实现JS Eval

可能重复: C#eval等价? 重复如何动态评估C#代码? 我们如何在C#中实现JS eval()如果可能的话提供一个例子..谢谢

在WCF中使用会话

以下是我在WCF应用程序中使用Session要做的事情: System.Guid guid = System.Guid.NewGuid(); string id = guid.ToString(); HttpContext.Current.Session[id] = “AnyThing”; 但我收到此错误消息: 对象引用未设置为Object的实例。 这是在WCF应用程序中使用Session的正确方法吗? 或者是否有另一种方法在WCF中存储数据?

‘SAPI不实现语音字母选择’例外

每当我尝试在我的笔记本电脑中编写任何语音识别程序时,我总会得到与下面提到的相同的消息。我总是可以编译我的代码并使Windows窗体应用程序正常工作。但问题是,程序无法检测到我的声音……程序不会工作.. 我非常确定我的代码工作正常,因为我通常从youtubevideo中获取代码: https : //www.youtube.com/watch?v = KR0-UYUGYgA等等。我使用的是.NET framework 4客户端配置文件对于我的项目..我只参考“system.speech”……可能是我的问题? 我得到的调试消息: speaker.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection. A first chance exception of type ‘System.Runtime.InteropServices.COMException’ occurred in System.Speech.dll A first chance exception of type ‘System.InvalidOperationException’ occurred in System.Speech.dll A first chance exception of type ‘System.InvalidOperationException’ occurred in System.Speech.dll A first chance exception […]

绑定工作没有INotifyPropertyChanged,为什么?

这就是我们通常的做法: public class ViewModel : INotifyPropertyChanged { string _test; public string Test { get { return _test; } set { _test = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName] string property = “”) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property)); } 现在我们的属性可以被视图中的多个元素使用,例如: 更改TextBox值将更新TextBlock内容。 我们可以在视图模型中设置值,视图会自动更新。 如果我们写这样的视图模型 public class ViewModel { public string Test { get; […]

在WindowsFormsHost上使用RenderTargetBitmap

我在WindowsFormsHost有一组控件,我想捕获当前视图并将其保存为图像,但是我只能在图像中看到一些Panel 。 是否可以将WindowsFormsHost用作“Visual”并捕获包装的控件? 看我的例子: 如果我basePanel添加一个Button或其他内容,那么在使用以下代码导出到PNG时,这将不可见: RenderTargetBitmap rtb = new RenderTargetBitmap(basePanel.Width, basePanel.Height, 96, 96, PixelFormats.Pbgra32); rtb.Render(windowHost); PngBitmapEncoder pnge = new PngBitmapEncoder(); pnge.Frames.Add(BitmapFrame.Create(rtb)); Stream stream = File.Create(“test.jpg”); pnge.Save(stream); stream.Close(); 关于为什么这可能不起作用的建议,也许是可能的解决办法? 我想这不是真的想用这种方式工作,但人们真的希望!