Menu
  • HOME
  • TAGS

Does System.Array Really Implement ICollection?

c#,arrays,icollection

It's explicitly implemented like so: int ICollection.Count { get { return Length; } } You can read more about explicit interface implementation on MSDN....

how to use hashtable in Linq

c#,linq,hashtable,icollection

You should not use non-generic HashTable to start with. Use generic Dictionary<int, string> instead: var d = new Dictionary<int, string>(); d.Add(1 , "ABC"); d.Add(2 , "AgC"); d.Add(3 , "ABC"); d.Add(4 , "AhC"); var posi = from a in d where a.Value == "ABC" select a.Key; ...

LINQ related error "Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context

asp.net-mvc,database,linq,icollection

It's kind of difficult to say what exactly is causing the error but I can see 3 possible culprits: 1) You're using .Equals() with a Linq to entities (L2E) query. This can cause problems, see here. 2) You say the error occurs on the line where List<ICollection<room>> is declared. On...

Get ICollection property of generic type

c#,linq,asp.net-mvc-5,icollection

Your query will take place right away since you are using SingleOrDefault(), see this StackOverflow question pertaining to SingleOrDefault() Your Include(s => s.Emisor) sticks out to me though. Since Emisor wasn't included when fetching the user, you will not be able to request that since your query is no longer...

How to iterate over @Model.ICollection in Java Script function?

javascript,.net,asp.net-mvc,razor,icollection

This should do it using JsonConvert from newtonsoft.json <script> var coordinatesJson='@Html.Raw(JsonConvert.Serialize(Model.LoginCoordinates.ToArray())' var coordinates=JSON.parse(coordinatesJson); //you now have coordinates as javascript object var map; function InitializeMap() { // could loop over if needed for(var coords in coordinates) { // do something with coords } </script> ...

Creating and editing a collection of strings using MVC3

c#,asp.net-mvc-3,model-view-controller,icollection

You need to create an EditorTemplate for Keyword, for example In /Views/Shared/EditorTemplates/Keyword.cshtml (add divs, class names etc as required) @model Keyword @Html.HiddenFor(m => m.KeywordId) @Html.LabelFor(m => m.KeywordTerm) @Html.TextBoxFor(m => m.KeywordTerm) @Html.ValidationMessageFor(m => m.KeywordTerm) Then in the main view Html.EditorFor(m=> m.Keywords) Note I have omitted the collection property Modules, but if...

Add items to ICollection

c#,icollection

List<Attempt> attempts= new List<Attempt>(); //Create a Instance of Attempt Attempt objAtt = new Attempt(); Guid id = new Guid(); objtAtt.Id =id; objtAtt.Time = DateTime.Now; objAtt.AttemptsMetaData ="test"; objAtt.Answered = true; objAtt.Disconnected = DateTime.Now; attempts.Add(objAtt); Here you pass to method, AddTask(attempts); Your method like this, public void AddTask(List<Attempt> attempts) { } ...

Collection of key-value pairs where only key type is known

c#,generics,icollection,keyvaluepair

Note beforehand : As a personal preference I tend to use dictionary for key/value pairs with unique keys or multimap/ilookup when i need duplicate key inputs. If you use C# 3.5 or older you can use var dic = new Dictionary<string, object>(); Assuming you're on C# 4 you can use...

Enumerated list of child class not working

c#,asp.net-mvc,view,icollection

In your foreach loop @foreach (var item in Model.TicketNotes) item is already an instance of TicketNote, so @Html.DisplayFor(modelItem => item.TicketNotes.Note) fails because TicketNote does not have a property named TicketNotes It should be just @Html.DisplayFor(m => item.Note) For the table headings, you can use @Html.DisplayNameFor(model => model.TicketNotes[0].Note) ...

Posting Nested Collection to Web API

c#,asp.net-web-api,binding,icollection

I think you need to create a model binder like this: Post([ModelBinder(typeof(MyClassModelBinder))] MyClass myClass) How to do it please read the following article: parameter binding in aspnet web api...

Get Count on Entity with ICollection that has specific property value

c#,linq,count,icollection

Here you go, var count = _db.Renders.Count(render => render.Comments.Any(c => c.CommentApproved)); ...

C# thread safe Collection with upper bound

c#,icollection

The simplest solution is just make a wrapper class that uses a normal dictionary and uses a ReaderWriterLockSlim to control thread safe access. public class SizeLimitedDictionary<TKey, TValue> : IDictionary<TKey, TValue> { private readonly int _maxSize; private readonly IDictionary<TKey, TValue> _dictionary; private readonly ReaderWriterLockSlim _readerWriterLock; public SizeLimitedDictionary(int maxSize) { _maxSize =...

MVC5 with EF6 : EditorFor() with an ICollection

asp.net-mvc,asp.net-mvc-5,entity-framework-6,editorfor,icollection

Thanks to Fals, it's now working with : <div class="form-group"> @Html.LabelFor(model => model.Days, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Days, "Day") @Html.ValidationMessageFor(model => model.Days) </div> </div> To display the textbox as a HTML5 DatePicker, don't forget to add a DateTime.cshtml in the EditorTemplates with the...