linq

Silverlight C# LINQ to XML

I'm working on a Silverlight web application that works with XML similar to: <?xml version="1.0" encoding="UTF-8" ?> <ProjectList> <Type>web</Type> <Project> <Id>1</Id> <Name>test web project</Name> <Description>test web project</Description> <ScreenshotList> <Screenshot> <Path>screen1.jpg</...

How write a LINQ expression that will return the maximum value of a field?

public class MyData { public int Value1 { get; set; } public int Value2 { get; set; } public int Value3 { get; set; } } public class MyViewData { List<MyData> MyDatas = new List<MyData>(); public int GetMaxValue(Expression<Func<MyData, int>> action) { // get highest value of specified field in MyDatas, retur...

Outer join in LINQ Problem

Id like to perform an outer join with the second join statement in this query, I keep getting weird errors! (it must be the 3rd RedBull) var Objeto = from t in Table1.All() join su in table2.All() on t.Id equals su.Id join tab2 in Table1.All() on t.PId equals tab2.Id //<-I want it here select new ...

Update all properties in list using linq

I need to update all the properties in a list object using linq. For ex.: I have an User List with (Name, Email, PhoneNo,...) as properties. I will get the Users List(List<Users>) from database which is filled with all properties except Email. I need to update all the Email property in the list after retrieving from database with some...

Know the number of elements of a Iqueryable

I have this Linq Query public IQueryable listAll() { ModelQMDataContext db = new ModelQMDataContext(); IQueryable lTax = from t in db.tax select new {Tax = t.tax1, Increase = t.increase}; return lTax; } how can I know the number of elements of lTax? Thanks. ...

C++ LINQ-like iterator operations

Having been tainted by Linq, I'm reluctant to give it up. However, for some things I just need to use C++. The real strength of linq as a linq-consumer (i.e. to me) lies not in expression trees (which are complex to manipulate), but the ease with which I can mix and match various functions. Do the equivalents of .Where, .Select and ....

nhibernate.linq simple (read dumb) question

I'm trying to wrap my head around linq -> nhib I have a simple bit of sql that i'm trying to get working in nhibernate.linq select * from ColModel where ColModel.DataIndex not in ('CostElement1', 'CostElement2', 'CostElement3') and ColModel.ReportId = 1 The list of excluded DataIndex values comes in in the form of a List<string...

LINQ: Checking if a field (db) contains items in an ILIST ?

Hi there, I am trying to create an extension method that i can forward a IList of statuses and check weather they exist, I thought the best way to do this was an ILIST - but maybe i wrong? Is this the best way to pass multple items to a method - A List? Its a generic LIST so hence no conversion etc from Object. Basically I have this as...

SubSonic Outer Join

There seems to be a Bug with the Outer Join statement in SubSonic 3, or maybe it's just my ignorance, but the following craps out: var Objeto = from t in Table1.All() join su in table2.All() on t.Id equals su.Id join tab2 in Table1.All() on t.PId equals tab2.Id into gj from j in gj.DefaultIfEmpty()...

LINQ: help with "contains" and a Lambda query

Hi there, I have a list which contains enums, its a standard Enum but has an attribute attached to it and an extension method which returns a CHAR of the enum (see below - GetCharValue), the extension works great. Now I have (another extension method for linq) public static IQueryable<Building> WithStatus(this IQueryable<Building...

building method for LINQ query to strip chars from records

I need to strip the following chars from my records using LINQ to SQL query "\";:'.,=+!@#$%^&*(_)~{}[]\\|<>? aeiouAEIOU" I can do it with my linq query here from p in customers select new {customer_name = String.Concat(p.First_name.Replace("A","@"),p.Last_name.Replace("A","@")), address = p.Address.Replace("A","@") } but I know th...

Create single permutation with Linq in C#

I have a code: List<int> list = new List<int>(); for (int i = 1; i <= n; i++) list.Add(i); Can I create this List<int> in one line with Linq? ...

Linq to SQL data source best practice

When using linq to SQL in my project I am currently creating the data context as late as possible in the code execution and disposing it as soon as possible. This results in the data context being open and closed many times on a page. Another option is to open the data class on page load and dispose it on page unload so the connection i...

What is a LINQ provider?

What is a "LINQ provider," and what is its purpose? ...

Dynamic LINQ API - SQL Convert Function

I'm trying to use a Dynamic LINQ Query to query a SQL database, and in the Where clause I need to evaluate an '=' condition with a field that is of type TEXT. Right now, I've got this: var result = DBCon.PcInValue .Where(String.Format("InputName = @0 and InputValue) {0} @1", f.Condition), f.Field, f.Value) .Select("new(OrderNum, ...

LINQ "table" variable

I'm trying to turn a method I have right now into a more "generic" method that returns a string. Right now, the method uses a statement like this: var app = (from d in testContext.DAPPs where d.sserID == (Guid)user.ProviderUserKey select d).ToList(); I process the results of "app", add extra text etc. The piece that change...

EntitySet Querying

I'm trying to run a query similar to var results = MyItem.MyEntitySet.Where( x => x.PropertyB == 0 ) MyEntitySet has one association, PropertyA, with MyItem. Ideally, the underlying SQL query should be SELECT .. FROM .. WHERE ([t0].[PropertyA] = @p0) AND ([t0].[PropertyB ] = @p1) since PropertyA and PropertyB are the two primary ...

Linq / data object best practices

I am a new asp.net programmer and I just asked this question which left me with a more general one. What is/are the current best practices regarding Linq and data objects? Specifically when to; dim, new and dispose of them. Also what about objects that get used in many different scopes on the same page e.g. a user data object. Should t...

LINQ to XML And Distinct Custom Class

I have a very interesting LINQ question. I have a document, that I am trying to filter results on, but to filter, I am matching on a REGEX result from one element of the XML. I have the following, working LINQ to XML to get the individual data that I'm looking for. Dim oDocument As XDocument oDocument = XDocument.Load("test.xml") Dim ...

Linq doesn't recognize changes in the database

Hi, I did not find something simular so i have to ask: I use linq to SQL and all was fine until i started to use Stored Procedures to update the database entries. (My Stored Proc is something like update all entries which groupid x) The Update runs fine and the values in the database change. But the DataContext ignores this changes. ...