linq

Convert CollectionBase to List or data type usable with Linq

Hi I am using Aspose cells to manipulate Excel spreadsheets. One of the types in the API is a collection of Pictures in the spreadsheet, which derives from CollectionBase: see this link: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/aspose.cells.pictures.html I want to convert this type to something that al...

LINQ: Associations not functioning correctly for use with innerjoins

Hi there, Can anyone help, I have been using linq2sql with great success using my associations (foreign keys) to provide inner joins etc... for example this, works great, the color is stored in a table called Color which has association so i pick it up via Color.Description - Excellent. Same for StructureType its actually an associati...

LINQ: Using a pivot table in linq

Hi there, Can anyone help? I have the following structure using associations, and as you can see v.StructureType.Description works great as its a 1 to 1 association, but i need to get in my example below v.StructureGroup.StructureGroupTariffs.Tariff.Price but StructureGroupTariffs is a Pivot table to interlink the StructureGroup and Ta...

c# xml element() select element where not defined

hi i have created the following xml <Fields xmlns="http://tempuri.org/XMLSchema1.xsd:Fields"&gt; <Field Name="ServiceProviderName"> <ID>0</ID> </Field> <Field Name="TransactionNumber"> <ID>1</ID> <Padding Length="8" PadChar="0"/> ...

return column values as IEnumerable

I have this code working: public IEnumerable<string> GetEmpNames() { var cmd = SqlCommand("select [EmpName] from [dbo].[Emp]"); using (var rdr = cmd.ExecuteReader()) while (rdr.Read()) yield return (string) rdr["EmpName"]; } However, I'm wondering if there's a better (LINQish) way, not having to resort to y...

Linq2Sql - Storing Linq Expressions in cleartext (linq) for future dynamic execution.

Hello everyone, I recently posted this: http://stackoverflow.com/questions/1558269/linq2sql-storing-complex-linq-queries-for-future-dynamic-execuction-raw-text It answered one question, but sent me down a different path because of the subQuery needing to reference the same table the original query already exists in. I was able to do...

Applying Group By in LINQ

I decided to group the collection by length of the string.Need suggestion from you to correct myself. string[] collection = {"five","four","ten","one"}; var GroupedValues = from w in collection group w by w.Length into GetByGroup select GetByGroup; for...

How to get a custom object out of a List<> with LINQ?

In the example below, why is product null? using System.Collections.Generic; using System.Linq; namespace TestEventsds343 { public class Program { static void Main(string[] args) { Product product = Product.LoadProduct(222); } } public class Product { public int ProductNu...

Difference between two "where"s in LINQ

Kindly let me know the difference between the "where" in (1) and "where()" in (2). When to use "where" and "where()" ? List<Person> pList = new List<Person> { new Person {EmpNo=1,FirstName="Marc",LastName="Loel",Salary=3434}, new Person {EmpNo=2, FirstName="Steve",LastName="Kaith",Salary=45...

How to get the Point with minimal X from an array of Points without using OrderBy?

Imagine I have var points = new Point[] { new Point(1, 2), new Point(2, 3) }; To get the point with the minimum X I could: var result = points.OrderBy(point => point.X).First(); But for large arrays, I don't think this is the faster option. There is a faster alternative? ...

How do I query a collection of objects in LINQ by a child property?

I'm new to linq and having trouble writing two simple queries. For some reason, I cannot wrap my head around it. its a simple structure: an Order has OrderItems. each orderItem has a productID. I would like to: get all orders that ordered productId 3 get all orders that ordered productId 4 AND 5 on the same order. I've tried it ...

how to convert the result in var to DataTable without Loop

How can i convert result in var to datatable without loop? Following is my code:- var result = PhysicianLookUp.Find(Where.PhysicianLookUp.DateTimeStamp.Ge(DateTimeStamp)); ...

specific VB Linq Query help

I am still new to LINQ, and I have wrestled with a query for several days and am ready to surrender to ignorance on this one. I need to: join 3 tables (on a total of 2 databases). Lets call them Table1 Table2 Table3 Table1 joins to Table2 on "org" the result joins to Table3 on "emplid" Filters (where): Table3.success = true Table3...

Linq - Top value form each group

How can i employ Linq to select Top value from each group when i have a code segment like : var teams = new Team[] { new Team{PlayerName="Ricky",TeamName="Australia", PlayerScore=234}, new Team{PlayerName="Hussy",TeamName="Australia", PlayerScore=134}, new Team{PlayerName="Clark",TeamName="Australia", PlayerScore=334}, new T...

linq grouping by custom class

I'm using linq on a DataTable (in c#), and was wondering how to group by multiple fields. I discovered that it can be done with an anonymous class, e.g. var a = dt.AsEnumerable().GroupBy(e => new { name = e["Name"] }) problem is, my grouping key is dynamically determined at runtime. so I instead tried grouping by a Dictionary instead:...

Linq equivalent to SQL LIKE [a-f]

SELECT * FROM Customer WHERE Name 'LIKE [a-f]%' How Can I acheive this in Linq?? In other words in linq how can i select all Names between a and f?? Thanks, ...

Using LINQ query on Dictionary and List .

Hi All, I have a Dictionary<int, int> idsAndTypes = new Dictionary<int, int>(); and i have a List<Product> products = new List<Product>() as list of products , the product class is as below class Product { public int Id {get;set;} public int Type{get;set;} } the dictionary idsAndTypes contains id's and types , now i want to use...

Reason not to use LINQ

Are there any good Reasons not to use LINQ in my projcts? We use .Net 3.5 and VSTO 3.0. ...

Linq- Running Total and Sub Total

I tried out some code to get the "running total" and "subtotal" ,but that did yield successful result. When the code is given: var salesPeople = new SalesPerson[] { new SalesPerson{Name="Ricky", RegionCode="R001",SalesAmount=100, SalesDate=Convert.ToDateTime("01/Jan/2009")}, new SalesPerson{Name="Mark", RegionCode="R001",SalesAmount...

When IQueryable is created from a linq query why is it not a "new" variable?

I am using the Entity Framework and have got a loop that looks at a set of People and using a foreach loop creates a query for the address of each person. As each address query is created it is added to the node of a treeview where it can be later used (to populate children nodes): IQueryable<Person> pQuery = (IQueryable<Person>)myCont...