linq

Good Fast Way to Let Users Visualize and Explore Relational Data?

I'm looking for either a web-based or Windows-based way to point to a relational data source using automated schema exploration (or, even better, a reflection-based approach that would work on any IQueryable in-memory data source) and allow easy exploration of data, traversing between records in related tables, etc. Basically a dynamic ...

LINQ Cast Enumerable to List of specific type

I am trying to formulate a LINQ query to select a sublist of a list where it meets a where condition like so: List<Entities.Base> bases = this.GetAllBases(); List<Entities.Base> thebases = from aBase in bases where aBase.OfficeCD == officeCD select aBase; where Base is just...

LINQ: Select <contition> OR <condition>

Pseudo code: SELECT * FROM 'table' WHERE ('date' < today) OR ('visible' = false) How do you do OR in Linq? ...

How to enumerate over nested enumerators.

I have a variable IEnumerable<IEnumerable<int>>. I'm trying to somehow aggregate it into an IEnumerable<int> which enumerates over all the integers in order. (All the integers from the first set, then all the integers from the second, etc.) I looked into LINQ's aggregate method, but the only examples I found was string concatenation, and...

Access to modified closure... but why?

Saw several similar questions here, but none of them seemed to quite be my issue... I understand (or thought I understood) the concept of closure, and understand what would cause Resharper to complain about access to a modified closure, but in the below code I don't understand how I'm breaching closure. Because primaryApps is declar...

Linq in C# Query needed - One to many table relationship, one to many records needed.

need help to accomplish this in linq. I have 3 tables. Customers CustumerOrder OrderDetails I need to list in one query all customers ( only if they have placed atleast one order) with all the orders for each customer only if order value is greated than 100. Regards, Harsh ...

Linq-to-object slowness. Now I'm just downright confused.

Okay, to build on my previous question: http://stackoverflow.com/questions/3999761/generically-checking-for-null-that-wont-box-nullables-on-a-non-constrained-type One user suggested putting a constraint for class and for struct and I also implemented the UnboxT pattern of specializing for the three types and storing that logic in delega...

Get an acronym from a string in C# using LINQ?

Here is how I would write a function to make an acronym in Java style: string makeAcronym(string str) { string result = ""; for (int i = 0; i < str.Length; i++) { if (i == 0 && str[i].ToString() != " ") { result += str[i]; continue; } ...

More elegant way to deserialize Json with LINQ?

I have data of the following form: { "sections" : [ { "section" : { "Term" : "News", "Term ID" : "4,253" } }, { "section" : { "Term" : "Sports", "Term ID" : "4,254" } }, // ... ] } I would like to serialize it into a collection of the following class: publ...

How to use join to make this queries cleaner?

I have the feeling that using joins could make this cleaner public override string[] GetRolesForUser(string username) { using (TemplateEntities ctx = new TemplateEntities()) { using (TransactionScope tran = new TransactionScope()) { int userId = (from u in ctx.Users where u.UserName == u...

manually build linq expression for x => x.Child == itemToCompare.Child

We have an object and we want to build a linq query based on that object on the fly. This linq statement is equivalent to what we want to build: Expression<Func<Sample, bool>> linqExpression = x => x.Child == itemToCompare.Child; We can't quite come up with the right expression to build the itemToCompare.Child part. Here'...

Dictionary Manipulation Using LINQ in C#

I'm having a Dictionary like Dictionary<String, List<String>> MyDict = new Dictionary<string, List<string>> { {"One",new List<String>{"A","B","C"}},{"Two",new List<String>{"A","C","D"}} }; I need to get a List<String> from this dictionary, The List should contain Distinct items from the values of the above ...

how to sort list in c#

i want to sort a list in c# like where structure property AVC goes to true then show them first then AVC goes to false. are any way to do this in c# linq ...

LINQ on a LinkedList - iterate over LinkedListNode<T>, not T

Hello SO; I'm having a problem understanding how to do something in LINQ. I have a linkedlist, the type of the object doesn't matter. What does matter is that I want to do something in a Where() based on the relationship between the current object and the next one in the list. Why can't I do something like: linkedlist.Where(n=>a_fun...

linq to sql datacontext, inserting objects and retrieving the id and appending it to another table??

Wierd question title... What i am trying to accomplish is pretty simple i think. I got 3 tables in the database, BlogPost - BlogPostTagsConnection - Tags The blogpost contains text, title, slug, author, id etc. The BlogPostTagsConnection contains the BlogPost id and the Tags id and finally the Tags contains tagid and tag. So i tried...

C# : How to add data data from a ListView control to a Dictionary.

The list view is like i need to add the data from the Listview to a Dictionary<String,String>. Now i'm using for loop to do this. Is there any way to do this using LINQ. Finally the Dictionary will contain {"A","1"} {"B","2"} {"C","3"} EDIT My code : Dictionary<String, String> Dic = new Dictionary<string, string>(); ...

C#:Conversion of Dictionary<String,String> to Dictionary<String, Dictionary<String,String>>

The First Dictionary is like Dictionary<String, String> ParentDict = new Dictionary<String, String>(); ParentDict.Add("A_1", "1"); ParentDict.Add("A_2", "2"); ParentDict.Add("B_1", "3"); ParentDict.Add("B_2", "4"); ParentDict.Add("C_1", "5"); i need to convert this into a new Dictionary...

Select random images using Linq/C#?

I am trying to select existing images from a directory. The image files are being renamed dynamically when they are created but the format they currently have cannot be changed. This is an example. client_2010_10_23_001.jpg Essentially, the images are names according to upload time and incremented. Perhaps split the file name into ...

Is it correct to have 2 methods from my repository running in the same controller ActionResult?

I am creating a store with ASP.NET 4.0 MVC and C# and am fairly new to it. I have come to creating the View page that displays the products within a certain category. On the specific category page I want to have the product list and also want the category name with its relevant description taken from the database. Currently the way I ...

Entity Framework 4: C# code to translate Microsoft SQL 2005/2008 row_number to a field?

Is .Skip().Take() the only way to get paging in Entity Framework? Is there some way to select the row number in the output so I could use Where( p => p.row > 9 && p.row <21)? select top 100 ROW_NUMBER() over (order by ID) as row, * from myTable I would think the ROW_Number() field must exist in the generated SQL for it to know what ...