草庐IT

CURRENT_AS_PATHNAME

全部标签

c# - 林克 "Could not translate expression... into SQL and could not treat it as a local expression."

我从thisquestion开始,我有点回答there,现在我在这里问更基本的问题。我已将查询简化为:varq=fromentinLinqUtils.GetTable()fromtelinent.Telephones.DefaultIfEmpty()selectnew{Name=ent.FormattedName,Tel=tel!=null?tel.FormattedNumber:""//thisiswhatcausestheerror};tel.FormattedNumber是一种将Number和Extension字段组合成格式整齐的字符串的属性。这是导致的错误:System.Inv

c# - 在此上下文中仅支持原始类型 ('such as Int32, String, and Guid' )

我收到以下错误:Unabletocreateaconstantvalueoftype'Phoenix.Intranet.Web.ClientSettings.ComponentRole'.Onlyprimitivetypes('suchasInt32,String,andGuid')aresupportedinthiscontext.我明白为什么会出现这个错误。我不明白的是为什么我的代码会产生错误。我的比较是针对原始类型的。所有的比较都是Guid到Guid。该错误明确指出Guids正常。错误发生在这一行(靠近底部):varvla=(fromcirinphoenixEntities.Co

c# - 调试器可视化工具和 "Type is not marked as serializable"

我正在尝试创建一个调试器可视化工具,它会显示任何Control的控件层次结构。它已完成,但我收到异常“类型未标记为可序列化”。我该如何克服呢?控件是.NETWindows窗体框架类型,我无法将其标记为可序列化。 最佳答案 您还需要实现VisualizerObjectSource执行自定义序列化。例子:publicclassControlVisualizerObjectSource:VisualizerObjectSource{publicoverridevoidGetData(objecttarget,StreamoutgoingD

c# - HttpContext.Current.Session 与 Context.Session

它们是一回事吗?或者它们有什么不同?我读过这个SOpost和this但他们比较的是HttpContext.Current.Session和Session而不是Context.Session。我错过了什么/误解了什么? 最佳答案 Context.Session在与HttpContext.Current.Session相同的页面中。HttpContext.Current.Session通常从不直接在页面上或没有对当前页面的引用的代码中使用。 关于c#-HttpContext.Current.

C#6 : nameof() current property in getter/setter

有没有办法在getter/setter中获取当前属性的名称?像这样:publicstringMyProperty{get{returnbase.Get(nameof(ThisProperty));}set{base.Set(nameof(ThisProperty),value);}}nameof(ThisProperty)应该解析为“MyProperty”。 最佳答案 nameof无法做到这一点,但有更好的方法(自C#5起可用)。您可以使propertyName参数可选,并将CallerMemberName属性应用于它:protec

c# - 控制台应用程序中的 Application.Current "null"

我目前正在尝试使用WPF组件,该组件利用WPF应用程序中的Application.Current,但是由于多种原因,我从不调用Application.Run(也不是一个选项)。结果是NullReferenceException。我主要是想从一个控制台应用程序中显示同一个WPF窗口的多个实例。欢迎任何建议(以及C#/F#中的代码示例)!提前致谢 最佳答案 只是提供一个替代解决方案。可以在不打开任何窗口的情况下保持应用程序运行。对我来说,这感觉不那么“hackish”。:)http://msdn.microsoft.com/en-us/

c# - 使用 Hangfire,Startup.cs 中给出的连接字符串抛出 Cannot attach file as database 错误

我在我的ASP.NetMVCWeb应用程序中使用Hangfire,它已成功安装。我想使用相同的LocalDb来存储排队的作业,以便Hangfire出队和处理,就像我用来存储数据一样。但是,当我在Startp.cs中提供在Web.config中定义的连接字符串或名称时,我遇到了以下错误。在hangfire之前,我在同一个localDb中添加、删除更新数据没有遇到任何问题。Cannotattachthefile'c:\users\jerry_dev\documents\visualstudio2013\Projects\Hangfire.Highlighter\Hangfire.Highl

c# - 系统参数异常 : Complex DataBinding accepts as a data source either an IList or an IListSource

我正在使用下面的C#代码来填充WinFormsListBox。但是我想隐藏所有系统文件夹。例如$RecyclingBin。但它给了我以下错误。System.ArgumentException:ComplexDataBindingacceptsasadatasourceeitheranIListoranIListSource.作为LINQ的新手,这让我很困惑。谁能告诉我哪里出错了?string[]dirs=Directory.GetDirectories(@"c:\");vardir=fromdindirswhere!d.StartsWith("$")selectd;listBox.Da

c# - 更改 IEnumerator<T>.Current 的属性

今天我很惊讶地观察到以下行为:给定一个类classFoo{propintFooNumber{get;set;}}和这段代码IEnumerablefoos=Enumerable.Range(0,3).Select(newFoo());foreach(varfooinfoos)foo.Bar=5;foreach(varfooinfoos)Console.Write(foo.Bar);//Writes000初始化时foos至newList{newFoo(),newFoo(),newFoo()}使循环写入“555”。我的问题:为什么会发生这种情况,有没有办法在不使用.ToList()的情况下避

c# - 为什么在测试受约束的泛型类型时直接转换失败但 "as"运算符成功?

``在编译一些使用具有类型约束的泛型的C#代码时,我遇到了一个有趣的好奇心。我写了一个快速测试用例来说明。我在VisualStudio2010中使用.NET4.0。namespaceTestCast{publicclassFruit{}publicclassApple:Fruit{}publicstaticclassTest{publicstaticvoidTestFruit(FruitTypefruit)whereFruitType:Fruit{if(fruitisApple){Appleapple=(Apple)fruit;}}}}转换为Apple失败并出现错误:“无法将类型‘Fr