linq

Getting mapped rows from IQueryable<ForeignKey> in Linq2Sql

The situation is: a webpage displays a listing of Gatherings to a logged-in user. Among this Queryable group might be Gatherings that the user is subscribed to but has not yet viewed until loading this page. Now that the Gatherings have been viewed by this user, I want to mark them as such. I can get this to work by using ToList() and C...

Dynamically setting LINQ datasource results in Operator '==' incompatible with operand types 'String' and 'Int32'

I'm trying to dynamically set my where statements for a linq datasource, and it was working fine until I try to add another constraint. This code works here: private void SetDataSourceWhereStatement() { HttpCookie cookie = Request.Cookies[ "CustomerID" ]; if ( cookie == null ) ...

Count occurrences of values across multiple columns

I am having a terrible time finding a solution to what I am sure is a simple problem. I started an app with data in Lists of objects. It's pertinent objects used to look like this (very simplified): class A { int[] Nums; } and List<A> myListOfA; I wanted to count occurrences of values in the member array over all the List....

Find the number of divisors of a number given an array of prime factors using LINQ

Given an array of prime factors of a natural number, how can I find the total number of divisors using LINQ upon the original array? I've already figured out most of this problem, but I'm having trouble with my LINQ statement. Math Background: The prime factors of a number are the prime integers that divide evenly into the number wi...

Possible to do a union in LINQ ?

Hi, From what I understand about the where clause in LINQ, it combines elements from two or more sets based on all possible combinations of each element and then applies the criteria. For example: public static void Main(string[] args) { var setA = new[] {3, 4, 5}; var setB = new[] {6, 7, 8}; var result = from a in setA ...

How to convert List<Company> to List<ICompany>

Hi I would like to convert List<Company> to List<ICompany> ICompany is an interface which Company implements. public List<ICompany> FindAll() { List<Company> companies = new List<Company>(); var query = from c in _scope.Extent<Company>() select c; companies = query.ToList(); return companies.ToList<I...

For developers, is it worth it to learn/use SSIS?

I'm starting to get involved in quite a bit of ETL work a my current job, and everyone seems to be pretty partial to SSIS. I'm struggling trying to do the most trivial transformations through BI studio that would usually equate to a couple foreach loops with a pinch of LINQ. Im not sure of the use cases or users this tool would be usef...

linq to entities qustion

Hi Experts, I am working on a project for automobiles listing. I am using linq to entities. I have a table listing and corresponding a class Listing in my data model. Listing { Listingid, AccountID, MakeId, ModelId } I have lookup table where I keep all the lookup values for makes and models. Lookupvalues { id, Description } I...

Get Random number of lines from textfile with group by

I want to get random number of lines(let's say 2 ) group by Code from text file. for e.g. 4581511:         50.27:        AT 1223522:         86.99:        AT 7456117:         68.59:        QW 5261789:         39.17:        QW ..... ..... Text File bookNumber      Price     Code 4581511:   ...

Finding what methods a LINQ provider supports

I just tried to use Contains in an Entity Framework query only to have it fail as this method doesn't exist in EF. However the code compiles which is frustrating. Does anyone know how to find which methods a LINQ provider supports, given any LINQ provider? ...

How can I shorten this linq to sql query?

Hi I am am making a calendar and to make it easier on myself I break up appointments that span over multiple weeks. For instance Jan 1st to Jan 31st spans like 6 weeks(my calendar is always 42 cells - 6 by 7). So I would basically have 6 rows stored in my database. However somethings I do require to me to put all these rows back toget...

Help with linq2sql generic lambda expression

In my Database almost every table has its own translations table. I.e. Sports has SportsTranslations table with columns: SportId, LanguageId, Name. At the moment I'm taking translations like: int[] defaultLanguages = { 1, 3 }; var query = from s in dc.Sports select new { sportName = s...

Compare DataRow collection to List<T>

I have a List<string> and I have a DataTable. One of the columns in a DataRow is ID. The List holds instances of this ID. The DataTable gets populated on a Timer. I want to return items from the List that are not in the DataTable into another list. ...

sqlmetal: how to preserve names for foreign keys without cutting the first name

Sqlmetal creates "embedded" properties for any foreign key it finds for table. Nice. The problem is when I have several foreign keys which refers to the same (foreign) table. This I like: FK_Company_Post then I can write in code: company.Post But this I don't like -- cutting suffixes: FK_Company_Post_HQ FK_Company_Post_Mailing ...

ElementAt() doesn't work in Linq to SubSonic

I have this query: var iterator = criteria.binaryAssetBranchNodeIds.GetEnumerator(); iterator.MoveNext(); var binaryAssetStructures = from bas in db.BinaryAssetStructures where bas.BinaryAssetStructureId == iterator.Current select bas; When I iterate over the binaryAssetStruc...

WCF LINQ CSLA Problem

I have a solution that uses CSLA for Business Layer and LINQ to SQL on another. We need to use WCF so that we can host our database on remote servers but it seems that the application cannot read the web.config file in WCF project using ContextManager. We tried using ConnectionManager and somehow it worked. Is there a known issue with Co...

How can I map my LINQ to SQL grouped result to this existing interface?

I have a LINQ to SQL query that returns a grouped collection of Sponsor objects like so: var result = ( from s in db.Sponsors join sl in sb.SponsorLevels on s.SponsorLevelId equals sl.SponsorLevelId select new Sponsor { Name = s.Name, Level = sl.LevelName ...

Can I compress an if statement using linq in C#?

In sql, I can make an if statement like the following If MY_STATE in (1,2,3,4) In C# I have to type if(MY_STATE == STATE.CT || MY_STATE == STATE.MA || MY_STATE == STATE.VA || MY_STATE == STATE.RI) This is obviously more clunky. Can I use LINQ to mimic the "in" statement of sql? I'm looking for something like if(MY_STATE in (STATE.CT, ...

LINQ-NHibernate - Selecting only a few fields (including a Collection) for a complex object

I'm using Fluent NHibernate in one of my projects (and ASP.NET MVC application), with LINQ to query to data (using the LINQ to NHibernate libraries). The objet names are changed to protect the innocent. Let's say I have the following classes Foo, Bar, Baz, and their appropriate tables in the database (MySQL). Foo has a many-to-many re...

Is there something like LINQ for Java?

Started to learn LINQ with C#. Especially LINQ to Objects and LINQ to XML. I really enjoy the power of LINQ. I learned that there is something called JLINQ a Jscript implementation. Also (as Catbert posted) Scala will have LINQ Do you know if LINQ or something similar will be a part of Java 7? Update: Interesting post from 2008 - http...