linq

Linq grouping based on other groups

I am storing transactions in a table. These transactions have an ID which relates to their parent node in a hierarchy tree. An example of my tree is shown in the image below. I need to allow an end user to retrieve the transaction and group them however they want as they are then written to a file based on the grouping. In the image belo...

Text file , CVS xml or what are my options ?

I want to develop an app for Windows 7 phone. It will be a GRE vocab app. i dont want to use SQL CE, my app will have 3 tables conceptually. I will be using Linq to SQL to querying data. Now i am confuse how should i store data so it is easy for retrival and update. XML , CSV , XML or any other format ? ...

Condensing linq expressions into one expression for a simple blog system

I currently have many linq expressions nested within foreach loops ... kind of defeating the point of using linq! What I'm trying to achieve is a simple blog model (blog posts which have multiple tags and are associated with multiple categories... that's all). I'm looking for a way to condense all my linq expressions into a single expr...

Getting rid of nested foreach loops when using linq

I am always finding myself creating linq expressions that still use nested foreach loops heavily. Below is a simple example of what I'm talking about, and I'd really appreciate it if someone on here can show me how to condense this low-efficiency code into a single linq expression? The database context (db) has three tables: Blog, Tag, ...

Linq to Entity update Query Part II

Ok, got my query going, up and running but it doesn't appear that I have got it working correctly!! My query is as follows: MyEnt updatefeedback = new MyEnt(); tblWeight newfeedback = ( from weight in updatefeedback.tblWeights where weight.MemberId == memberid where weight.LocationId == locationid where weight.PriKey =...

Linq to add outer list index to inner elements

Let's say I have a list of lists { { 'a', 'b', 'c'}, {'d', 'e', 'f'} } How can I project these to a flat list of the form: { {'a', 0}, {'b', 0}, {'c', 0}, {'d', 1}, {'e', 1}, {'f', 1}} where the 2nd field of each resulting element is the index of the inner list ? ...

RavenDB paging index

I have a Linq query as var mdls = (from mdl in query dbSession.Query<MyModel>("MyIndex") orderby mdl.Name select dept).Skip(page.Value).Take(4); Where "MyIndex" is a simple index defined in RavenDB. I know that while querying an Index in RavenDB it returns "TotalResults". See here How can i get the query r...

Using Entity Framework 4 to search inside two comma separated lists

I have an entity that has a property called YearsAvailible, this is a comma separated list of financial years e.g. 05,09,10 I have an API that is passes a string[] of year names and I need to search for all of the entity that have a financial year that is in the passed array. The best I can come up with is this: var hash = new Hashtabl...

Linq for NHibernate Event Listener

I have an implementation of IPostLoadEventListener which converts DateTime properties from UTC in our database to the user's local time zone. This works fine when working with NHibernate entities using Session.Get, but I can't find a way to get Linq for Nhibernate to observe the event listener, which means the DateTime properties on any...

order datatable by relevance using linq by column values which are comma sperated

I have a Datatable that contains a column called Tags, Tags can have values such as row[0] = Tag1 row[1] = Tag1, Tag2 row[2] = Tag2, Tag3 row[3] = Tag1, Tag2, Tag3 row[4] = Tag4, Tag6 and are seperated by comma's etc.. I have the value of Tags for the current document and have run a query to select all other documents that have eith...

Find the highest number in a set to be rounded down, and round it up instead

As the title describes, I have a set of objects - call them Allocations - which contain a description & a number. All numbers in the set add up to 100%, but for display purpose I sometimes round to a whole percent. In some edge cases, having rounded the numbers I end up with 99%. Example: Description | Actual | Rounded ==============...

Sorting collection and sub-collection at the same time.

I have an IQueryable<Product> that needs to be sorted by Name. Each Product has an IQueryable<Category> that also needs to be sorted by Name. I'm having a hard time expressing this in Linq. I could loop through the products and sort each category list, but it seems messy. Hoping a Linq ninja has a smarter solution. My Product class look...

Error message: 'OfType' is not a member of 'System.Text.....

Well the full error is Error 3 'OfType' is not a member of 'System.Text.RegularExpressions.MatchCollection' in the following lines of code, (curly braces in regex.Matches(input).OfType) For Each group As Object In regex.Matches(input).OfType(Of Match)().Select(Function(c) c.Value.ToLowerInvariant()).Where(Function(c) Not keywords.Con...

Linq Expression string with inline values

I am trying to build expression strings for use with IOC extended nHydrate. When I call ToString() on my expression I get something like this: employee => employee.Username == value( Some type name here ) Is there a way to resolve that value call to the actual value? employee => employee.Username == "Captain Spiffy" ...

Can I accept both a delegate type T and an Expression<T> in the same parameter?

I'm trying to write a helper class that represents fields on an object. The helper class needs to be able to both get the value of the field on a given instance AND return metadata about the underlying property that it can obtain by reflection. I'd like the helper class be created by a utility method that gets called something like the ...

How do I create a dynamic where clause using a List in LINQ to SQL?

var query_loc = (from at in db.amenities_types join a in db.amenities on at.id equals a.amenities_type join u in db.unitInfos on a.unit_id equals u.id join l in db.locations on u.locations_id equals l.id join o in db.organizations on l.organization_id eq...

Using linq to get list of web controls of certain type in a web page

Is there a way to use linq to get a list of textboxes in a web page regardless of their position in the tree hierarchy or containers. So instead of looping through the ControlCollection of each container to find the textboxes, do the same thing in linq, maybe in a single linq statement? ...

Linq paging - how to solve performance problem?

Edit: Entity Framework seems to be the issue, discussed further in question Entity Framework & Linq performance problem. I am supporting a PagedList (using linq/generics) class written by someone long departed - and it has 2 lines that have very bad performance - on a dataset of just 2 thousand rows it takes up to one minute to run. Th...

Order of List using Linq is not the same as sort

I would like to confirm this, I was trying to sort a List of my class using Linq. But it seems the order of the data was not ordering the same way when i used a sort function. Assume that the list contains 4 ComputeItem and all their A are set to 1, the B, C, D of all are set to zero. CASE 1: ItemList = ItemList .OrderByD...

Entity Framework & Linq performance problem

I have a performance problem with Entity Framework and Linq, when paging a list of Product objects: var data =_service.GetAll(); var page = data.Skip((index) * pageSize).Take(pageSize); list.Add(page.AsEnumerable); // ** its slow right here There are 1958 products in my test database, but when the above code runs I can see 3916 (that...