草庐IT

language-reference

全部标签

c# - 获取 "Tuple element name is inferred. Please use language version 7.1 or greater to access an element by its inferred name."

直到今天,在我们将VisualStudio2017更新到最新的15.3之后,我们的UWP应用程序中的以下代码一直运行良好。privatevoidTest(){vargroups=newListitems)>();varitems=newList{("a",true),("b",false),("c",false)};vargroup=(Guid.NewGuid(),items);groups.Add(group);}在输出窗口中没有错误信息但是这个Tupleelementname'items'isinferred.Pleaseuselanguageversion7.1orgreater

c# - 如何构建 LINQ to Entities 查询以直接加载子对象,而不是调用 Reference 属性或 Load()

我刚开始使用LINQtoEntities(或EntityFramework,不管他们怎么调用它),我正在编写很多这样的代码:varitem=(fromInventoryItemitemindb.Inventorywhereitem.ID==idselectitem).First();然后像这样在该对象上调用方法:vartype=item.ItemTypeReference;或varorders=item.OrderLineItems.Load();检索子对象或相关对象。我没有分析数据库或挖掘得太深,但我的猜测是,当我调用.Load()或*Reference属性时,我实际上是在对数据库进

c# - 我收到错误 "The DELETE statement conflicted with the REFERENCE constraint"

我尝试用外键截断表并收到消息:"CannottruncatetablebecauseitisbeingreferencedbyaFOREIGNKEYconstraint".我阅读了很多有关该问题的文献,并认为我通过使用delete找到了解决方案DELETEFROMtable_nameDBCCCHECKIDENT(table_name,RESEED,0)但我仍然收到错误消息:"TheDELETEstatementconflictedwiththeREFERENCEconstraint".当我尝试使用MicrosoftManagementStudio删除并执行之前的查询时DELETEFRO

c# - 错误 : "The specified LINQ expression contains references to queries that are associated with different contexts"

我从LINQ查询中收到标题中显示的错误,该查询包含来自两个不同edmx文件的两个表。这是查询:varquery=(fromaindb1.Table1joinbindb1.Table2ona.Idequalsb.Idorderbya.Statuswhereb.Id==1&&a.Status=="new"selectnew{Id=a.Id,CompanyId=(fromcindb2.Companywheres.Id==a.Idselectnew{c.CompanyId})});db1和db2是与两个不同的edmx文件关联的上下文。我该如何克服这个错误? 最佳答案

C# 反射 : How to get class reference from string?

我想在C#中执行此操作,但我不知道如何:我有一个带有类名的字符串-例如:FooClass我想在这个类上调用一个(静态)方法:FooClass.MyMethod();显然,我需要通过反射找到对类的引用,但是如何呢? 最佳答案 您将要使用Type.GetType方法。这是一个非常简单的例子:usingSystem;usingSystem.Reflection;classProgram{staticvoidMain(){Typet=Type.GetType("Foo");MethodInfomethod=t.GetMethod("Bar"

c# - lock(new object()) -- cargo 崇拜或一些疯狂的 "language special case"?

我正在审查一位顾问编写的一些代码,虽然已经出现了数十个危险信号,但我无法理解以下代码片段:privatevoidfoo(){if(InvokeRequired){lock(newobject()){if(m_bar!=null)Invoke(newfooDelegate(foo),newobject[]{});}}else{if(OnBazChanged!=null)OnBazChanged();}}lock(newobject())在这里做什么?应该没有任何影响,因为它总是锁定另一个对象,但这种锁定在整个代码中都是持久的,即使在非复制和粘贴的部分也是如此。这是C#语言中的一些特殊情况

asp.net - 安装 ASP.NET 和 Web 工具 2015 后出现 Visual Studio 错误 "Object reference not set to an instance of an object"

安装ASP.NET和WebTools2015(RC1更新1)后,我在打开*.cshtml文件时在ASP.NETMVC4项目中收到以下错误:Objectreferencenotsettoinstanceofanobject即使我开始一个新的ASP.NETMVC4项目并尝试在那里打开一个*.cshtml文件,我也会收到相同的错误消息。我正在使用VisualStudio2015 最佳答案 也许这有帮助:从以下文件夹中删除内容:C:\Users\%userprofile%\AppData\Local\Microsoft\VisualStud

c# - 生成错误 : You must add a reference to System. 运行时

我正在准备一个全新的ASP.NETMVC5.1解决方案。我正在添加一堆NuGet包并使用ZurbFoundation等进行设置。作为其中的一部分,我添加了对内部NuGet包的引用,它是一个可移植类库,我认为这会导致构建服务器出现问题。TeamCity构建失败:Thetype'System.Object'isdefinedinanassemblythatisnotreferenced.Youmustaddareferencetoassembly'System.Runtime,Version=4.0.0.0我最初在编译Razor网页时为相同或相似的错误添加了修复程序,该修复程序位于web.

c# - CS0120 : An object reference is required for the nonstatic field, 方法或属性 'foo'

考虑:namespaceWindowsApplication1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){//int[]val={0,0};intval;if(textBox1.Text==""){MessageBox.Show("Inputanyno");}else{val=Convert.ToInt32(textBox1.Text);Threadot1=newThread(newParamete

javascript - 如何向 "GraphQL schema language"中的字段添加说明

我有一个graphql模式,其中的一个片段如下所示:typeUser{username:String!password:String!}在graphiql中,有一个描述字段,但它总是说“self描述”。如何向模式添加描述? 最佳答案 如果您使用的是GraphQL.js0.7.0或更高版本,您只需在要描述的字段、类型或参数之前直接添加注释即可。例如:#AtypethatdescribestheusertypeUser{#Theuser'susername,shouldbetypedintheloginfield.username:St