{"id":4226,"date":"2014-03-30T09:24:43","date_gmt":"2014-03-30T09:24:43","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-icollection-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:24:43","modified_gmt":"2014-03-30T09:24:43","slug":"problem-about-icollection-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-icollection-collection-of-common-programming-errors\/","title":{"rendered":"problem about icollection-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4a92d66111d2f71d36b14aec1741fb14?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCort3z<br \/>\ncasting asp.net-mvc-4 entity-framework-4.3 icollection<br \/>\nThis is the datamodel I have:public class Team {[Key]public int Id { get; set;} [Required]public string Name { get; set; }[MinLength(1)]public virtual ICollection&lt;User&gt; Users { get; set; } }My issue is that when I later try to create a new Team (that has one user) I get the following issue when the context is saving.An unexpected exception was thrown during validation of &#8216;Users&#8217; when invoking System.ComponentModel.DataAnnotations.MinLengthAttribute.IsValid. See the inner exception for deta<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/03587793af844fde75c6b86e9a8ff726?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSandy<br \/>\nc# generics c#-4.0 icollection<br \/>\nI am stuck with this simple looking code for over an hour now&#8230; I have few classes&#8230;and methods like this:abstract class ClassBase&lt;SampleInterface&gt; {\/\/Some methods};public class ClassAction1: ClassBase&lt;MyInterface&gt; {\/\/Some methods};public class ClassAction2: ClassBase&lt;MyInterface&gt; {\/\/Some methods};class SomeClass { public void AddClassRange(ICollection&lt;ClassBase&lt;MyInterface&gt;&gt; range){foreach (ClassBase&lt;MyInterface&gt; ClassBase in range)AddClass(ClassBase);}publ<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fadb4fcf41ff786e47d48e30e19af833?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKonrad Morawski<br \/>\nc# list interface casting icollection<br \/>\nI have classT, implementing interfaceIBar.I have a variable list of type List&lt;T&gt;.Two questions for enhancing my understanding of the language:Why doesn&#8217;t this work?var foo = (ICollection &lt;IBar&gt;)list; \/\/ fails! How to work around it (if possible)?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ecd5204b524b147737119ec92f31e5ca?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGivenPie<br \/>\nc# asp.net database dataset icollection<br \/>\nI&#8217;m opening up a database query from the Northwind database for each item that my ShoppingCart entails. It is to take ProductID and UnitsInStock out from the Products table. After I take the two columns out from the database to save the data into a DataTabel ds. Then I compare to make sure the quantity user entered is less than the column units in stock in the database.theCart.Values is part of ICollections.I am gettign error: from my exception message: &#8220;There was a problem connecting to the dat<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a648ccb47bbbe9497c073315aac4d33e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJoachim Sauer<br \/>\ncollections ienumerable generics icollection<br \/>\nI have a method with an object parameter.public bool ContainsValue(object value)I found that converting the object to an IList works.IList&lt;object&gt; list = (IList&lt;object&gt;)value;However, converting it to a List does not.List&lt;object&gt; Ilist = (List&lt;object&gt;)value;I looked at the definition of both the IList and the List and they both seem to implement the Enumerator and Collection interfaces. I am wondering why List doesn&#8217;t work but IList does. Where in the framework does it<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/xV2cq.jpg?s=32&amp;g=1\" \/><br \/>\n\u00c9ric<br \/>\nc# key-value icollection idictionary<br \/>\nI have a C# class that acts as a dictionary so I&#8217;m now in the process of supporting IDictionary.Everything is fine except for the properties Keys and Values:ICollection&lt;TKey&gt; Keys { get; } ICollection&lt;TValue&gt; Values { get; }I don&#8217;t have a collection of keys or values internally so I&#8217;m wondering how to provide these as a ICollection.My first attempt was to use the magic of &#8220;yield return&#8221; like this:ICollection&lt;TValue&gt; Values { get {for( int i = 0; i &lt; nbValues; ++i ) {yield re<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cort3z casting asp.net-mvc-4 entity-framework-4.3 icollection This is the datamodel I have:public class Team {[Key]public int Id { get; set;} [Required]public string Name { get; set; }[MinLength(1)]public virtual ICollection&lt;User&gt; Users { get; set; } }My issue is that when I later try to create a new Team (that has one user) I get the following issue [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4226","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4226"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4226\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}