w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Linq expression to filter an a list of entity's collection, and maintain list of entities
var r = Foos.Select(x => new Foo() { Id = x.Id, Name = x.Name, Bars = x.Bars.Where(y => y.Age <= 25 && y.Age >= 5).ToList() });

Categories : C#

Java Collection: what to convert Collection> to ArrayList> or List>?
You can use the appropriate constructor: List<List<String>> yourList = new ArrayList<>(yourCollection); The order of the elements in the list is the order of the iterator of the collection.

Categories : Java

Linq query to get filtred main collection and each list in result in that collection
This should be done in View Model (or Dto) layer, first, define your view models: public class RestaurantVM { public int Id { get; set; } public string Name { get; set; } public City City { get; set; } public List<MealVM> Meals { get; set; } } public class MealVM { public int Id { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public int Price { get; set; } public int Number { get; set; } public int Kind { get; set; } } Then you can write LINQ like below: var restaurantVMs = db.Restaurants .Include(rest => rest.Meals) .Where(rest => rest.City.Name == city) .AsEnumerable() .Select(r => new RestaurantVM(){

Categories : C#

"Value does not fall in expected range" List collection and not in Observable collection
Only thing which bugs me out here is "RaisePropertyChanged" is used with ObservableCollection or at least you must inherit INotifyPropertyChanged interface. In your second implementation list is not getting "RaisePropertyChanged" method. Consider list declaration as: private List<User> _Users; public List<User> Users { get { return _Users; } set { _Users = value;} } I think this should resolve the error. But NOTE that doing so will not raise PropertyChanged event whenever the state of the object changes (Added, Removed, and Modified) to the point where you want to notify the underlying collection or container that the state has changed. For more info read: List vs ObservableCollection vs INotifyPropertyChanged in Silverlight

Categories : C#

Can't bring content_id through to list of collection and then add to a collection ruby on rails
There is a RailsCast on how to properly do this : http://railscasts.com/episodes/163-self-referential-association Hope it helps someone out there!

Categories : Ruby On Rails

re-arranging a collection list based on another collection
Pipe your results through WITH and then order them. Then do the aggregation via RETURN as normal. START n=node(*) MATCH p=n-[r:LIKES]->items WITH n,r,items ORDER BY r.w DESC RETURN n,collect(r.w),collect(items.name);

Categories : Neo4j

How to select a sub collection available in a list of collection
Use SelectMany to get all locations and Distinct to make them distinct: Dim distinctLocations = entityProvider.GetProducts(). SelectMany(Function(p) p.Locations). Distinct()

Categories : Dotnet

Generate unique list item id for all list items in site collection
There is no comparable feature to the documentID service for Items in general out of the box. You would have to build it using Custom code. You can create a custom ID which appends the list GUID and the OOTB item ID which is unique to every item in the site collection.

Categories : Sharepoint

Why does Entity Framework only cascade single item in a collection?
i'm not that sure, but i think it's because of the virtual keyword in the id. You said it's code first, and a key in a db represent an immutable property. Allowing that parameter to be overridden is confusing, and probably not correct... Also the lists of subelements are defined as follow this.Widgets = new HashSet<Widget>(); wich is more generic of a list ... i'll give it a shot P.s. i've used model first

Categories : Entity Framework

Linq how to query a list of items for a combined list of a child collection based on a property of the parent item
You may just want to group the invoice headers by the group: var groups = invoiceHeader.GroupBy(ih => ih.Group); Then you can access the lines of the groups: foreach(var group in groups) { Console.WriteLine("Group " + group.Group); Console.WriteLine("Lines:"); Console.WriteLine(string.Join(", ", group.SelectMany(h => h.InvoiceHeader.InvoiceLines))); } Output would be something like Group A Lines: invoice1, invoice2, invoice3, invoice4 Group B Lines: invoice5, invoice6, invoice7, invoice8

Categories : C#

How to get a list of keys from a collection of list of properties with key value pairs
If your list is a collection of KeyValue pairs then can you not just iterate this collection and build up a new list of strings representing the Key Dim l2 As New List(Of String) For Each kvp As KeyValuePair(Of String, String) In res(0) l2.Add(kvp.Key) Next

Categories : Asp Net

LinQ: How to Write single Query to retrieve records while passing List/string collection in efficient way?
To pass in a bunch of Id's to a query to compare to Id's in the database, typically you would use a Contains call instead of looping through it (which will cause another query for each iteration of the loop, and will be quite slow). I can't quite gather how it would fit into your Entities since I'm not sure how the using (SupportEntity support = new SupportEntity()) portion would work, but here's a simple example: public IEnumerable<Car> GetCarsMatchingIds(IEnumerable<int> carIds) { using(var dealershipContext = new DealershipContext()) { return dealershipContext.Cars.Where(c => carIds.Contains(c.Id)); } }

Categories : Linq

java garbage collection does a <(major collection:mark and sweep> every time it does a
I would try removing all the settings you have so that you have the absolute minimum and you are less likely to get a strange interaction between settings Try just -Xmx16g -XX:+UseConcMarkSweepGC and monitor it using jstat

Categories : Java

Select All from Collection Where ID in List
This does what you need: var uniqUsers = allUsers.Where(x => migrated.Contains(x.salesIDs)) .OrderBy(y => y.lastNames) .GroupBy(z => z.salesIDs).SelectMany(v => v).ToList(); Gets all users where the salesID is in migrated, then orders by lastNames and then groups by the salesID. The SelectMany() will project the elements to a sequence, the ToList() will enumerate the results.

Categories : C#

How to access a List collection across winforms
You don't need to send a list as ref, the ref is only needed when changing the (pointer)instance itself. Adding/removing items doesn't affect the lists instance. Updated: The listbox uses the ToString() to present some description for the item. public class Item { public string @Url; public string Name; public double Price; public Item(string @url, string name, double price) { this.Url = url; this.Name = name; this.Price = price; } public void setPrice(Button button) { this.Price = Convert.ToDouble(button.Text); } public override string ToString() { // example: return string.Format("{0} -> {1}", this.Name, this.Price); return this.Price; } } So you should not add the name, but the o

Categories : C#

How to set a list of Models on a Collection with Backbone
You can use this.collection.models in your _.each function, or simply this.collection.each, as it's mixed in Backbone.Collection. However, I'm not sure if you want to recalculate it every time you render -- I guess this.parentTreeId doesn't change, so you may do it in initialize.

Categories : Backbone Js

How to update a element in List collection in C#
The easiest way is to using reflection. I do not know if you are using properties or fields. For properties code will look like: var target = listJoinedScreenDefinition[index]; Type type = target.GetType(); PropertyInfo prop = type.GetProperty("propertyName"); prop.SetValue (target, propertyValue, null); For fields code is very similar: var target = listJoinedScreenDefinition[index]; FieldInfo fi = target.GetType().GetField("Name", BindingFlags.NonPublic | BindingFlags.Instance); fi.SetValue(target ,value)

Categories : C#

filter child collection by list
Try this: from v in dataSource where v.Areas.Intersect(filter).Any() select v; This works because Intersect returns what both lists have in common, and if they have anything in common then they match.

Categories : Linq

Create a collection of sub collection from a given Collection (Group By) in Java
Probably this is what you need until java 8 closures comes HashMap<Integer, DateTileGrid> dataGridMap = new HashMap<>(); for (Date date: dateList) { int year = date.getYear(); //Deprecated.. use something better DateTileGrid dataGrid = dataGridMap.get(year); if(dataGrid == null){ dataGrid = new DateTileGrid(); dataGrid.setCurrentYear(year); dataGrid.setDateTiles(new ArrayList<Date>()); dataGridMap.put(year, dataGrid); } dataGrid.getDateTiles().add(date); } //Here is your result ArrayList<DateTileGrid> result = new ArrayList<>(dataGridMap.values());

Categories : Java

Best Collection to store a list of cards in Java?
I'd go with a List-based approach. Your requirements are rather vague, but a List provides a good foundation for what you want to do. I'd suggest wrapping a List in your Deck class (rather than having Deck extend a concrete List class such as ArrayList or LinkedList). All Deck behavior should be defined by the Deck class; you certainly don't want to be automatically inheriting all List behavior, as it may not all be appropriate for your Deck object.

Categories : Java

How to list items of a collection with Word Ole Automation
I found the solution so I'll share it with you :) Here is a sample code to list all paragraphs of the active document of the word editor : OleAutomation active = activeDocument.getAutomation(); if(active!=null){ int[] paragraphsId = getId(active, "Paragraphs"); if(paragraphsId.length > 0) { Variant vParagraphs = active.getProperty(paragraphsId[0]); if(vParagraphs != null){ OleAutomation paragraphs = vParagraphs.getAutomation(); if(paragraphs!=null){ int[] countId = getId(paragraphs, "Count"); if(countId.length > 0) { Variant count = paragraphs.getProperty(countId[0]); if(count!=null){ int numberOfParagraphs = count.getInt();

Categories : Java

Deserialize List to unmodifiable collection with gson
Why don't you just follow the JavaBean standards and just return unmodifiable lists? public class MyClass { private List<String> myList = new ArrayList<String>(); public void setMyList(List<String> list) { this.myList = list; } public Collection<String> getMyList() { return Collections.unmodifiablelist(this.myList); } }

Categories : Java

exporting mongodb collection into csv having list of subdocuments
I don't think that the CSV format allows you to split up a single document as multiple documents, as this is something that you would need if you have nested documents. It would most definitely not create multiple fields for each sub-document as you are expecting. If you want to do that, then you can quite easily write your own CSV exporter which allows you a lot more flexibility anyway.

Categories : Mongodb

Array / List / collection of objects of a class in R
Try using replicate nodeID <- replicate(100, new("node"), simplify="list") is(nodeID) # [1] "list" "vector" is(nodeID[[1]]) # [1] "node" Using something like nodeID[100] <- new("node") as you found, does not work. What that (is attempting) to do is look for an object called nodeID and if found, try to set its 100th element to new("node"). It does not, say, create an object nodeID and populate it with 100 elements. Also, notice that you can avoid your for loop by instead using, say, lapply: eg, instead of: for(i in 1:dim(nodeID)) { nodeID[i]@capacity <- 1000 blah blah.... } use: lapply(nodeID, function(n) {blah balh...} )

Categories : R

Any collection object to hold list of combination of more than 2 elements?
class MyContainer { String someString; int someInt; } List <MyContainer> myList = new List<>(); Something like that!? I don´t know exactly, what you mean by "Creating an object for this is not a good idea in my case". You could as an alternative create a List<Object> and put in whatever you have or even a List<List<Object>> if you want to have a List of a number of grouped objects.

Categories : Java

Use only list/collection to store data locally on webpage
I got one solution for you. This is just a sample implementation. Please modify according your requirement. The Code : using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace BindingListSample { public partial class _Default : System.Web.UI.Page { static List<Employee> bindingL = new List<Employee>(); protected void Btn_Click(object sender, EventArgs e) { bindingL.Add(new Employee { Name = TxtName.Text }); GrvSample.DataSource = bindingL; GrvSample.DataBind(); } } public class Employee { public string Name { get; set; } } } The problem is that you need t

Categories : C#

C# readonly access to List<> or other collection, or ToArray() magic
For read only collection you could use List<T>.AsReadOnly() public IList<int> MyCollection { get{ return _myCollection==null ? null : _myCollection.AsReadOnly(); } If necessary and in order to make more clear that we're talking about a read only collection you could define your property like this public IReadOnlyList<int> MyCollection

Categories : C#

Collection safer than standard list with generic type?
I suggest using the standard Collections: List<Integer> checked = Collections.checkedList(list, Integer.class); then just work on checked. A ClassCastException will be thrown during the insertion of any non-compliant instance - sooner (thus better) than before (i.e. during retrieval). N.B. check your compiler messages, I'd bet you have some warnings printed in there mentioning unsafe/unchecked code.. Your problem is exactly what the compiler is trying to tell you. If you control the signature of add, make it generic - it will give you compile-time safety. public static <T> void add(List<T> list, T t) { list.add(t); }

Categories : Java

Lamda Expression to order (sort) my list collection
You can add another property. class mymodel { public string Name{ get; set; } public string AMPM{ get; set; } public int AMPM_Sort { get { if (AMPM == "AM") return 1; if (AMPM == "PM") return 2; if (AMPM == "MIX") return 3; if (AMPM == "--") return 4; return 9; } } } List<mymodel> mylist; var sorted = mylist.OrderBy(x => x.AMPM_Sort);

Categories : C#

How to manage two list object reference that are pointing to same collection?
It's hard to tell what you're asking, but if you're trying to keep a copy of the original list you will need to make a copy instead of assigning the reference. frmPrepare.lstBtn = Program.currOrder.OrderItems[currIdx].AppliedCustomization; frmPrepare.actualBtnLIst = frmPrepare.lstBtn.ToList(); // ToList will create a copy of each item reference in the collection.

Categories : C#

mongdb pymongo disappearing list of items from collection
This line: things = collection.find() actually returns a Cursor (docs): Returns an instance of Cursor corresponding to this query. So, when you create a list from the things Cursor, the entire results from the find query are returned and copied into first_list. The second time, the Cursor instance stored in things is at the end of the results, so, there are no more to populate second_list.

Categories : Python

Select RDF collection/list and iterate result with Jena
Selecting Lists (and Elements) in SPARQL Let's address the SPARQL issue first. I've modified your data just a little bit so that the elements have different values, so it will be easier to see them in the output. Here's the data in N3 format, which is a bit more concise, especially when representing lists: @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix blah: <http://www.something.org/stuff#> . <http://www.something.org/stuff/some_entity1> blah:myitems ([ a blah:myitem ; blah:myitemvalue1 "1" ; blah:myitemvalue2 "2" ] [ a blah:myitem ; blah:myitemvalue1 "3" ; blah:myitemvalue2 "4" ]) ; blah:stringid "string1" ;

Categories : List

How to get the distinct list of ids from the Mongo Collection by datetime ordering?
This is tricky, because each distinct value for _stdid can have a different dateTime field value. Which one do you want to pick? The first, the last, the average? You will also need to use the aggregation framework, and not a straight distinct. On the MongoDB shell, you would use (if you wanted the first of all the dateTime values that map to a single _stdid field): db.messages.aggregate( [ { $group: { _id: '$_stdid', dateTime : { $first: '$dateTime' } } }, { $sort: { dateTime : -1 } } ] ); In Java, this looks like: // create our pipeline operations, first with the $group operation DBObject groupFields = new BasicDBObject( "_id", "$_stdid" ); groupFields.put( "dateTime", new BasicDBObject( "$first", "$dateTime" ) ); DBObject group = new BasicDBObject( "$group", groupFields );

Categories : Mongodb

How to Hide specific value in a dropdown (a collection list) in Rails?
Just remove it from the collection <%= collection_select(:feedback, :department_id, Department.where("name <> 'admin'").order('name ASC'), :id, :name) %>

Categories : Ruby On Rails

Adding new users to a collection and having them render on a list automatically?
So I assume then that "player" records belong to a user in some way? So when you create a new user, you create their new default player record? Maybe you just need your helpers to check that a player record for the user exists, and if not, create it. Template.leaderboard.players = function () { var players = Players.find({/* Get players for this user */ }, {sort: {score: -1, name: 1}}); if(!players) { players = /* Insert default player record */ } return players; };

Categories : Meteor

Getting list of string(Collection) from an object using hibernate criteria
About you question: no, this projection is not possible because collection of elements has the same lifecycle of owner entity Getting collections of elements with criteria is not possibile (read here). You have to work with native SQL to return List<String>.

Categories : Java

Sort a Collection of POJOs based on a List of integers
Divide and conquer, first sort both lists independently and then merge them together, comparing the first elements of both lists each time you iterate (using your comparator). This is the most efficient way. You can sort both lists with the default java sorting.

Categories : Java

How to show collection fields from bcs in infopath list item form?
it is possible by using code behind hybrid solution. http://manojssharepointblog.wordpress.com/2013/02/05/create-infopath-form-with-lookup-functionality-to-sharepoint-list/ this link should help you

Categories : Sharepoint

List Collection Filtering using Where condition giving null values
This code (reformatted to avoid scrolling): IList<EFModel.EntityModel.vwGetActiveEmployee> managerlist = activeEmployeelist.Where(p => p.IsManager == 1) .Select(p => p) as IList<EFModel.EntityModel.vwGetActiveEmployee>; ... will always give managerlist as a null, as Select doesn't return an IList<T> in any implementation I've ever seen. I suspect you want: IList<vwGetActiveEmployee> managerlist = activeEmployeelist.Where(p => p.IsManager == 1) .ToList(); Note that unless you're deliberately performing a reference type conversion which can validly fail (in which case you should usually be checking the result against null) you should prefer casts instead of as. If you'd used a cast here, yo

Categories : C#

Extracting several models from a Backbone Collection that matches List of Model IDs
filter is useful for this sort of thing. If you would like, you can wrap it nicely in the definition of your collection object: Facilities = Backbone.Collection.extend({ // ... getAllForCodes: function(facilityCodes) { var models = this.filter(function(facility) { return (_.indexOf(facilityCodes, facility.get('FacilityCode')) !== -1); }); return new Facilities(models); } }); ...and the use it to get all facilities for an array of facility codes: var myFacilities = facilities.getAllForCodes([1, 2, 3]);

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.