linq

How can I perform this query using L2E?

Hi, I have a 2 tables: Activities ActivityKeywords ********** **************** ID --> ActivityID Name Keyword I need to return all activities that match a specific keyword. ...

Will bad things happen to me if I name my arrays, collections, lists, enumerables, etc. just the plural of what they contain?

I have always thought it was "best practice" to be explicit in naming my collection variables. So, if I had a collection of Car objects, I would typically name a Car[] carArray and a List<Car> carList. And then 99% of the time, I end up just doing something like... foreach (Car car in carArray) { ... } ...and I'm thinking, I coul...

LINQ: Get first character of each string in an array

Consider a string array shaped like this: string[] someName = new string[] { "First", "MiddleName", "LastName" }; The requirement is to get the first character from each element in the array. i.e. FML Previously have tried: string initials = string.Concat(someName.Select(x => x[0])); Question: What LINQ query would you wri...

Subsonic 3.0.0.3 SQL Paging using Linq

Have just updated from Subsonic 2.2 ActiveRecord to 3.0.0.3. I am trying to use LINQ to do a paged Find query like this (my object/table is called "Repository"): Repository.Find(item => item.DocumentTitle.Contains(searchTerm)) .OrderBy(i => i.DocumentTitle).Skip((currentPage - 1) * itemsPerPage) .Take(itemsPerPage); When I v...

Moq Query Never Returning

I'm not sure what i'm doing wrong, but this line of code is never returning (seems to result in a run-away process) when running it in a test: var discountMemberCustomer = (from customer in Mocks.Query<Customer>() where customer.IsDiscountMember && customer.OrderCount == 13 && customer.LifetimeCustomerValue == 5555m ...

Cast linq results to List<MyInterface>

Hi, I have extended my entities to implement specific interfaces for its type. I am trying to perform the following query: var results = from x in context.MyEntityTable where x.AProperty == AValue select x; return results.Count() > 0 ? results.Cast<IApplicationEntity>().ToList() : null; However, I kee...

Linq inner join grouping

I'm trying to create an expression tree dynamicly. Let asume that I have two simple classes: class CustomerType { public int Id { get; set; } public string Name { get; set; } public OrderType[] Orders { get; set; } } class OrderType { public int Id { get; set; } public DateTime Date { get; set; } public decimal Pric...

combine join with String.Contains in Linq query

i have the following linq query that create a left join between two tables: var joinResultRows = from leftTable in dataSet.Tables[leftTableName].AsEnumerable() join rightTable in dataSet.Tables[rightTableName].AsEnumerable() on...

LINQtoCRM and DynamicEntity

I found LINQtoCRM (http://linqtocrm.codeplex.com/) and I started playing with it. It's nice, but before I get carried away I found there appears to be a showstopper: I can't figure out how to query against DynamicEntities (so I can query against my custom entities). Can someone confirm if this is currently impossible? Or give an example ...

Count, orderby and group in LINQ

Given a set Paris New York London New York Paris Paris I'm trying to do a LINQ query that will return a grouping of the Paris, New York, and London with their respective counts. I've been able to do a GroupBy that returns a group containing only the Paris/New York/London in each Grouping. Sounds relatively simple, but I can't get it ...

Ranges with Linq and dictionaries.

I've created a Range type: public class Range<T> where T : IComparable<T> { public Range(T min, T max) : this(min, max, false) { } public Range(T min, T max, bool upperbound) { } public bool Upperbound { get; private set; } public T Min { get; private set; } public T Max { get; private set; } public bool ...

LINQ Product of two fields in aggregated query

Hi, I need to calculate a sum of product of two fields. This will be used for average weighted price. avgPrice = sum( price*volume) / sum(volume). Both price1 and price2 return error "Specified cast is not valid." var result3 = from sym in dataTableAsEnumerable() group sym by new { symbol = sym["symbol"] } into ...

LINQ2SQL - Cross join emitted when I want inner join

This emits inner joins, which is what I want and works: var q = from itm in esdc.items join itmImg in esdc.itemImages on itm.itemId equals itmImg.itemId join itmIdent in esdc.itemIdentities on itm.imgIdentityId equals itmIdent.itemIdentityId join startImgs in esdc.vStartPgImgs on itmImg.imgId equals startImgs.imgId s...

Improve db4o linq query

Hello, I got a problem with this linq query: from PersistedFileInfo fi in m_Database from PersistedCommit commit in m_Database where commit.FileIDs.Contains( fi.ID ) where fi.Path == <given path> select new Commit( m_Storage, commit ); As you can see, every PersistedCommit contains a Collection<int> called FileIDs which connects it t...

Reading values from xml file with Linq

I'm having troubles reading values from an xml file. Here is the xml file: <root> <defaultGroups name="Sikker"> <group name="0ASK" /> <group name="0ASKAPP" /> <group name="0ASKFELLES" /> <group name="0SYSAPP" /> <group name="0SYSAPPoffice" /> <group name="10WTS" /> </defaultGroups>...

Linq Take() question

I want to filter my results to take only the X amount of records. I am wondering how does Take() work? On this site I found: http://www.hookedonlinq.com/TakeOperator.ashx It says Take() "Throws an ArgumentNullException if source is null." So what should I do? I can't guarantee that everytime I do a Take() I will have some records in t...

Subsonic 3.0: How to use LIKE on objects?

New to Subsonic 3.0 and wondering how to perform LIKE operators on object attributes. Given the following class, how would I perform a LIKE operation using Subsonic 3.0. For example SELECT * FROM categories WHERE name LIKE '%foo%'; public class Category { private String categoryID; private String name; public Category() ...

Distinct not working with LINQ to Objects

class Program { static void Main(string[] args) { List<Book> books = new List<Book> { new Book { Name="C# in depth", Authors = new List<Author> { new Author { FirstName = "Jon"...

Finding maximum number of rows created per hour?

I have a table to store product reviews like this: Id -int ProductId -int Timestamp -datetime Comments -text Is there an easy way to count and determine the rate of reviews a product has received in any 60 minute timespan? ie. Widget1 maximum reviews/hour is 55. working with sql05. ...

Difference between the LINQ join and sub from

Is there any difference between these two LINQ statements: var query = from a in entities.A where a.Name == "Something" from b in entities.B where a.Id == b.Id select b; var query = from a in entities.A join b in entities.B on a.Id equals b.Id w...