linq

MVC LINQ Query question

In my public ActionResult Active() { var list = _entity.CALL_UP.Where(s => s.STATE == ICallUpsState.FULLY_SIGNED) .Where(f => f.START_DATE <= DateTime.Today && f.END_DATE >= DateTime.Today) .ToList(); return View(list); } This r...

Rotate an array using LINQ syntax

I am solving this problem of rotating an array and got algorithm and code working int[] Rotate(int[] ar,int k) { if (k <= 0 || k > ar.Length - 1) return ar; Reverse(ar, 0, k - 1); Reverse(ar, k, ar.Length - 1); Reverse(ar, 0, ar.Length - 1); return ar; ...

Select X with Max(F(X))

I'm trying to write some AI for a game of checkers. I want to select the move with the highest board score. Need something like this: var bestMove = from m in validMoves where BoardScore(opp, board.Clone().ApplyMove(m)) is max select m Except I can't figure out the "is max" part. Would prefer it return...

Manipulating List<String> using Linq in C#

i've a List< String> like List<String> ListOne = new List<string> { "A-B", "B-C" }; i need to split each string if it contains '-' and add to the same list So the result will be like { "A-B", "B-C","A","B","C" }; Now i'm using like for (int i = 0; i < ListOne.Count; i++) { if (ListOne[i].Contains('...

Questions regarding How do i tutorial (WPF/Entity Framework/ObservableCollections)

i watched How Do I: Build a WPF Data Entry Form Using Entity Framework? very confused around 15:30. when the presenter said something like when you create a LINQ query, we wont get a rich collection ... whats does she mean my "rich". the start code looks like... whats wrong with that. even if i change db.Customers.Execute(...) ...

How can I clean up this LINQ Query (SelectMany) ?

How can I clean up this LINQ Query to use SelectMany in the sql syntax, instead of method chaining at the end like I have done? var runPeakWidths = (from ipa in runAnalysis.PassAnalyses let peakWidths = BuildPeakWidths(ipa) select peakWidths) .SelectMany(data => data); Edit: Turned into a tight little method: ...

autoincrement on table, will entity framework reflect on this before save changes?

My setup is this; first I'm defining a couple of new rows. newCompany = new company { companyInfo = value.company_info, companyName = value.company_name, organizationNumber = value.company_orgnr }; newContract = new contract { contra...

best way to convert collection to string

Hi I need to convert a collection of <string,string> to a single string containing all the values in the collection like KeyValueKeyValue... But How do I do this effectively? I have done it this way at the moment: parameters = string.Join("", requestParameters.Select(x => string.Concat(x.Key, x.Value))); But not sure it is the best...

DomainContext Load

I tried to load a entity by domainservice(async) in on line of code like: context.Load<Book>( context.Books.Where(b => b.BookID == 1), (s, e) => { _book = e.Results; }, null); But I got following error: The type 'SilverlightApplication1.Book' cannot be used as type parameter 'TEntity' in the generic type or method 'System.Service...

Is it possible to automatically prefix all table names in SQL Server and in LINQ to SQL?

I'm working on a few ASP.NET MVC projects which all require database functionality. Unfortunately, my hosting provider only gives me two SQL Server databases to work with, so I want to put the tables of multiple projects into a single database. However, some of my tables are similarly named, so I might run into some issues. Thus, I'm tr...

How can anonymous types be created using LINQ with lambda syntax ?

Hi, I have a LINQ query that uses lambda syntax: var query = books .Where(book => book.Length > 10) .OrderBy(book => book.Length) I would like to create an anonymous type to store the projection, similar to: var query = from book in books where book.Length > 10 orderby book sel...

Throw Exception if record is a foreign key in another table

UPDATE: Probably should model my database to my objects correctly first! Found this tutorial http://www.codeproject.com/KB/linq/linqtutorial.aspx so should probably ignore this question! Hi All, Apologies if this already has a thread but I cant seem to find the answer I am looking for. I have an object Communication Type: [Table(Name ...

What's your favorite LINQ to Objects operator which is not built-in?

With extension methods, we can write handy LINQ operators which solve generic problems. I want to hear which methods or overloads you are missing in the System.Linq namespace and how you implemented them. Clean and elegant implementations, maybe using existing methods, are preferred. ...

Avoiding repeated projection code in Entity Framework

I'm trying to solve a problem similar to the one described here http://stackoverflow.com/questions/1440289/initializing-strongly-typed-objects-in-linq-to-entities only from totally the opposite direction. I have a number of functions in my repository, all of which return identically shaped data. The issue is my projection code: selec...

Compare items in a List to each other, by a seperate function.

Hello, I have a function that checks whether a string represents a filesystemlocation beneath another string. My question however should be applicable to any function returning boolean. Here is the function anyway... private bool IsItemBelowPath(string item, string path) { if (path == Path.GetPathRoot(path)) { path = ...

ILookup versus IGrouping

ILookup and IGrouping are pretty similar Linq interfaces. Both bound a key to a list of values. The question is what differs these both interface. Does anyone have an example what you can do with one type that you are not able to todo with the other one? When should you use "group by" and when "to lookup"? ...

LINQ operators versus LINQ methods: limitations, pros / cons of one over the other?

What are the pros and cons of LINQ operators and LINQ methods? Does one have limitations or added capabilities the other does not? ...

help with LINQ join

Hi - I'd like to get some help on how to formulate this query: I Have a snapshot of the datamodel relevant to this question at: http://jdsign.dk/media/9221/dbdiagram.png To the method that should be created the input is a guid userid in the following called inputuserid. Please help me get: a list of all the subjects that have any note...

Is a join appropriate for accomplishing such functionality in LINQ to SQL?

I'm writing an ASP.NET MVC site where I'm using LINQ to SQL to access my SQL Server database. In my database, I have the following tables: Posts: PostID - int, PK, identity Text - nvarchar(MAX) PublishDate - datetime etc. PostTags: PostTagID - int, PK, identity PostID - FK to PK to Posts table TagID - FK to PK to Tags table Tags...

Left join on Linq?

I'm actually not sure if this is exactly a left join; I'm not an expert on SQL. I have the following Linq query: var title = dataSet.Tables["title"].AsEnumerable(); var author = dataSet.Tables["author"].AsEnumerable(); var review = dataSet.Tables["review"].AsEnumerable(); var results = from t in title ...