草庐IT

string-id

全部标签

c# - ReferentialConstraint 中的依赖属性映射到存储生成的列。列 : 'ID'

当我尝试添加Venue对象并调用SaveChanges()时,我不明白为什么会出现此错误。模型中与Venue对象的唯一区别是它们与City是1对1..0关系。Citycity=ProcessCityCache(ev,country,db);//Afterthiscall,'city'isalreadypersisted.venue=newVenue{TicketMasterURL=ev.VenueSeoLink,Name=Capitalize(ev.VenueName),City=city};db.Venues.AddObject(venue);db.SaveChanges();//E

C# HashSet<string> 到单个字符串

我有一个HashSet定期添加。我想要做的是在不执行foreach循环的情况下将整个HashSet转换为字符串。有人有例子吗? 最佳答案 无论您是否显式编写内容,您都将遍历内容。然而,如果没有明确的写作,如果你说“cast”是指“concatenate”,你会这样写stringoutput=string.Join("",yourSet);//.NET4.0stringoutput=string.Join("",yourSet.ToArray());//.NET3.5 关于C#HashSe

c# - ICollection<string> 到 string[]

我有一个ICollection类型的对象.转换为string[]的最佳方式是什么?.如何在.NET2中完成此操作?如何在更高版本的C#中更清晰地完成此操作,或许在C#3中使用LINQ? 最佳答案 您可以使用以下代码片段将其转换为普通数组:string[]array=newstring[collection.Count];collection.CopyTo(array,0);这应该可以完成工作:) 关于c#-ICollection到string[],我们在StackOverflow上找到一

C# Linq - 无法将 IEnumerable<string> 隐式转换为 List<string>

我有一个这样定义的列表:publicListAttachmentURLS;我正在像这样向列表中添加项目:instruction.AttachmentURLS=curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment=>!String.IsNullOrEmpty(Attachment));但我收到此错误:无法将IEnumerable隐式转换为列表我做错了什么? 最佳答案 Where方法返回IEnumerable.尝试添加.ToLis

c# - 如何将 XML 转换为 List<string> 或 String[]?

如何将以下XML转换为List或String[]:12 最佳答案 听起来您更多的是在解析之后而不是完整的XML序列化/反序列化。如果您可以使用LINQtoXML,这将非常简单:usingSystem;usingSystem.Linq;usingSystem.Xml.Linq;publicclassTest{staticvoidMain(){stringxml="12";XDocumentdoc=XDocument.Parse(xml);varlist=doc.Root.Elements("id").Select(element=>e

c# - 如何将 string[] 转换为 ArrayList?

我有一个字符串数组。如何将其转换为System.Collections.ArrayList? 最佳答案 string[]myStringArray=newstring[2];myStringArray[0]="G";myStringArray[1]="L";ArrayListmyArrayList=newArrayList();myArrayList.AddRange(myStringArray); 关于c#-如何将string[]转换为ArrayList?,我们在StackOverfl

c# - 如何在一行 C# 3.0 中将 object[] 转换为 List<string>?

好吧,我放弃了,你如何在一行中做到这一点?publicobjectConvert(object[]values,TypetargetType,objectparameter,System.Globalization.CultureInfoculture){//Listfields=values.ToList();//Listfields=valuesasList;//Listfields=(List)values;Listfields=newList();foreach(objectvalueinvalues){fields.Add(value.ToString());}//proce

c# - 为什么 asp.net Identity 用户 id 是字符串?

我想使用System.Guid类型作为我在asp.netwebapi应用程序中所有表的ID。但我也使用Asp.netIdentity,它使用string类型的id(也用于存储guid)。所以我想知道为什么它默认使用stringid而不是System.Guid?在所有应用程序中使用什么是更好的选择-Guidid或string-guidid?如果使用字符串-生成新ID的最合适和最可靠的方法是什么-在代码中还是在数据库中? 最佳答案 使用ASP.NETCore,您可以通过一种非常简单的方法来指定您想要用于Identity模型的数据类型。第

c# - 这段代码怎么可能: "ArgumentOutOfRangeException: startIndex cannot be larger than length of string"?

我的C#代码中有以下方法://////Removesthefirst(leftmost)occurenceofafroma.//////Thestringtoremovethefrom.Cannotbenull.///Thesubstringtolookforandremovefromthe.Cannotbenull.//////Therestofthe,afterthefirst(leftmost)occurenceoftheinit(ifany)hasbeenremoved.////////////Ifthedoesnotoccurwithinthe,theisreturnedin

c# - LINQ 到 SQL : Delete entity (by ID) with one query

我使用LINQToSQL已经有一段时间了,当谈到从数据库中删除实体时,我总是调用表的.DeleteOnSubmit并传入实体。有时我发现自己在写类似这样的东西:db.Users.DeleteOnSubmit(db.Users.Where(c=>c.ID==xyz).Select(c=>c).Single());这当然会导致两个查询。一个获取符合条件的实体,然后另一个删除它。通常我有需要删除的记录的ID,我想知道是否有更直接的方法仅通过ID从表中删除行? 最佳答案 通过附加部分对象并将其删除,无需手动工具SQL即可执行此操作:varm