linq

How can I turn these LINQ joins into LEFT OUTER joins?

var auditAgencyRecords = (from ag in db.Agencies join ara in db.AuditRuleAccounts on ag.Agency_Id equals ara.AgencyID join arr in db.AuditRuleResults on ara.AuditRuleAccountID equals arr.AuditRuleAccountID join are in db.Audi...

Why use AsQueryable() instead of List()

I'm getting into using the Repository Pattern for data access with the Entity Framework and LINQ as the underpinning of implementation of the non-Test Repository. Most samples I see return AsQueryable() when the call returns N records instead of List. Could someone tell me the advantage of doing this? Regards ...

Is there an easy way to return the FIRST LinqToXML result?

Ok, I have a LinqToXml query that returns a single record (correct terminology?), however, I don't want to use a for.. loop to pull that one record from the query. Is there an easier way? *bonus if you find a better way to write the query (I'm still learning) my xml file: <?xml version="1.0"?> <!-- first draft of LibMappings.xml fi...

Linq (MIN && MAX)

Hello All, What is equal of below sql in LINQ select MIN(finishTimestamp) AS FromDate, MAX(finishTimeStamp) AS ToDate From Transactions ?? from t in Transactions select new { FromDate = ?, ToDate = ? } Thanks ...

Linq where in between IENumerable and List<>

I have filled List<Object1> Object 1 contain 2 fields (int id & string name) Also i Have IEnumerable<Object2> Generated by linq2sql. With fields (id, name) i need to get items from List<Object1> which Id's are absent in IEnumerable<Object2>. by Key Field = id (like where in in sql..) i used code like IEnumerable Object2 List<Object1...

Why doesn't my LINQ to Objects query return any results?

I have the following query I'm using (which mostly came from the help I received here): public IEnumerable<Entities.AuditAgency> GetAuditRuleAgencyRecords(IEnumerable<Entities.AuditRuleEnterprise> rules) { using (LinqModelDataContext db = new LinqModelDataContext()) { // Left-Outer Joins on Agency and...

.NET / C# - Proper Method to Use Here - LINQ

I'm a total newb to LINQ. Here is the code I have so far: public class Folder { public Folder(string path) { string[] files = Directory.GetFiles(path); IList<FileInfo> fis = new List<FileInfo>(); files.SomeMethod(x => fis.Add(new FileInfo(x))); } } What is the correct method name to replace SomeMet...

Get List<> element position in c# using LINQ

I have a List with numbers, I'd like to find the position of the minimum (not value) using LINQ eg: {3,1,0,5} output = 2 ...

Swap List<> elements with c# using LINQ

I have this list var list = new List { 3, 1, 0, 5 }; I want to swap element 0 with 2 output 0, 1, 3, 5 ...

How to delete multiple rows based on a collection of non-primary key field items using LINQ-TO-SQL?

I have this columns id int primary key, code int not null I want to delete all items where code equals to one of the items in a IEnumerable<int> someEnumerable One possible way is using iteration. But I wanna do it without explicit iteration (for, foreach). Another way is by doing this: var result = db.table.Where(a => someEnumera...

How to display opening times?

Hi all, I'm trying to show intervals of working hours/days it's should look like this: I have table where I'm storing day number, open time and closing time for each day Then I created query=> var groups = from s in this.OpenTimes orderby s.Day group s by new { s.Till, s.Start } into gr select new { Time = gr.Key.Start + "-" + g...

Cannot figure out something fundamental about ASP.NET MVC (not working simple sample of code included)

Hello everybody. I am trying to learn some ASP.NET MVC. Please bear with me but asp.net mvc is the first mvc framework i ever tried to learn. I do plan to learn more about mvc framework in different languages, but for now i got asp.net mvc. I am fairly good with asp.net forms and love them, but would like to have another asp.net tool...

xml parsing problem with c# linq to xml - Reference to undeclared entity

tryin to parse an xml file gives me the following error Reference to undeclared entity 'eacute' after I created a dtd file with all the entities that I found here http://www.w3.org/TR/xhtml1/dtds.html and I loaded it as follows XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; string s = System.IO.Fi...

Is there any performance difference between myCollection.Where(...).FirstOrDefault() and myCollection.FirstOrDefault(...)

Is there any performance difference between myCollection.Where(...).FirstOrDefault() and myCollection.FirstOrDefault(...) Filling in the dots with the predicate you are using. ...

Using Linq SubmitChanges without TimeStamp and StoredProcedures the same time

I am using Sql tables without rowversion or timestamp. However, I need to use Linq to update certain values in the table. Since Linq cannot know which values to update, I am using a second DataContext to retrieve the current object from database and use both the database and the actual object as Input for the Attach method like so: Publ...

Why this Linq code always throws System.StackOverflowException?

//A query to a local object var deletionCommands = commands .Where(a => a.Operation != Operation.Addition) .Select(a => new { a.Prestador.cod_prestador, a.Prestador.cod_desdobramento }) ; //A Linq-To-SQL query var toDelete = db.Prestadors .Where(a => deletionCommands.Contains(new { a.cod_prestador, a.cod_desdobram...

How to Generate Combinations of Elements of a List<T> in .NET 4.0

I have a question that is similar, but not identical, to the one answered here. I would like a function generate all of the k-combinations of elements from a List of n elements. Note that I am looking for combinations, not permutations, and that we need a solution for varying k (i.e., hard-coding the loops is a no-no). I am looking fo...

C# + LINQ + ADO.NET EF , join 2 tables and return everything without specifying all fields manually

I have a simple LINQ query on ADO.NET Entity Framework as follows var result = from itemA in TableA join itemB in TableB on itemA.ID = itemB.ID select ?????? I am trying to select everything from itemA and itemB without specifying all the TableA and TableB. anything thoughts??? ...

How to make a C# 'grep' more Functional using LINQ?

I have a method that performs a simplistic 'grep' across files, using an enumerable of "search strings". (Effectively, I'm doing a very naive "Find All References") IEnumerable<string> searchStrings = GetSearchStrings(); IEnumerable<string> filesToLookIn = GetFiles(); MultiMap<string, string> references = new MultiMap<string, string>(...

How do I make my own Linq Clauses?

Is there a way I can create my own Linq Clauses? I have been looking into extension methods and it's not quite what I am looking for. I was thinking something like the where, the select or the from clause. I want to use my code like such var blah = from bleep in bloops where bleep == razzie myclause bleep.proper...