linq

Linq, simple filter error...C#

Hi, Using linq and silverlight got this error....I am using POCO....DTO = POCO public IEnumerable..... var query = from d in Context.Documentos where d.CodigoEquipamento == documentoDTO.CodigoEquipamento && d.Codigo == tipoEquipamentoDTO.Codigo select new DocumentoDTO { ...

Generic variadic parameters

Hi From dahlbyk answer to this question : http://stackoverflow.com/questions/4038978/map-two-lists-into-a-dictionary-in-c , Leppie wrote this comment: Pity there is a need for a Zip method. If only more statically typed languages would support generic variadic parameters, Select would handle this (like map in Scheme). – leppie What ...

Filter by criteriums in linq query

I have for example table cars table cars( producer varchar(30), model varchar(30), price integer, start datetime, end datetime) and I need to return data from table using criterions ( based on one criterion , or two or all of them ). Is there any way to dynamically create linq question (just one linq query, not to create for all combi...

Why do I have to call the Cast<> extension method on a DataGridViewRow?

This doesn't work. var result = from row in grid.Rows where (string) row.Cells["COLUMN_1"].Value == "Test" select row.Cells["COLUMN_2"].Value as int?; But this does. var result = from row in grid.Rows.Cast<DataGridViewRow>() where (string) row.Cells["COLUMN_1"].Value == "Test" select row.Cells["COLUMN_2"].Va...

How to add to target objects using XDocument and Linq?

I need to add a large portion of new generated xml to an existing xdoc but only for my nodes which contain a particular value for one of their children. Here's an example: XDocument originalXML = GetEntityXml(ref exportTile); XDocument newXML = testr(); XElement xe = new XElement("Subtiles"); ...

Linq to SQL with multiple Unions

I have a linq union statement that has been giving me some trouble and I can't see where the issue is. Any help would be appreciated. The error is.... All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists. I know the error means that I am selecting different amo...

Consolidate or reuse LINQ expression

I have a LINQ expression that gets used as a filer in a LINQ to SQL statement where clause. My problem is that the LINQ to SQL expression has become unwieldy and also the logic it contains has ended up in multiple locations violating DRY (this is the 3rd time I'm working on a bug raised by QA for it getting out of sync). Is there any wa...

Is it possible to perform set based property assignments with LINQ?

I'm trying to test just how far LINQ can really go. What i'm trying to achieve is property assignments on a list of objects with a single expression rather than for loops. I want to take all items in listA and update the IsMatched property, but only where there is a corresponding item in listB (which is a different type), is this possibl...

Is it possible to rewrite this tricky extension method?

Is it possible to rewrite this extension method without the parameter? public static string PropertyName<T>(this T obj, Expression<Func<T>> property) { var memberExpression = property.Body as MemberExpression; if (memberExpression == null) throw new ArgumentException("Expression must be a MemberExpression.", "property");...

C#, Linq data from EF troubles

Hello, I don't have much experience with programming. I am working (to learn) on a project. I am using C# 4.0 and WPF 4 with EF (SQLite). I am having problemw with LINQ. Here is the code in question (I hope this is enough, let me know if more is needed) private void cboSelectCompany_SelectionChanged(object sender, Selection...

LINQ where using index in query language

Is there anu posibility to write this using query language ... not method chain? notifications.Where((n, index) => n.EventId == m_lastSelectedEventID) .Select((n, index) => new {Position = index}).FirstOrDefault(); Thanks, Radu ...

SubSonic 3, build dynamic or expression at runtime

I have a situation where I have to dynamically build a linq query based on user selections. If I had to dynamically generate sql I could do it this way: var sb = new StringBuilder(); sb.AppendLine("SELECT * FROM products p"); sb.AppendLine("WHERE p.CategoryId > 5"); // these variables are not static but ...

Nhibernate LINQ - caching problems

Hello everybody I have the following code factory = new Configuration().Configure().BuildSessionFactory(); session = factory.OpenSession(); var query = session.Linq<Root>(); var data = query.ToList<Root>(); var data2 = query.ToList<Root>(); This one generate 2 SQL queries, so i understand that first level cache isn't working. Does LI...

IQueryable where iterating (this or this or this)

I have a dynamic list of values, which i want to query against an IQueryable with OR conditions. How would I foreach the values to "OR" them up against the IQueryable? ...

How to define IEnumerable behavior by contract?

Consider this 2 methods that returns IEnumerable: private IEnumerable<MyClass> GetYieldResult(int qtResult) { for (int i = 0; i < qtResult; i++) { count++; yield return new MyClass() { Id = i+1 }; } } private IEnumerable<MyClass> GetNonYieldResult(int qtResult) { ...

Why does this work and this doesn't?

public Form1() { InitializeComponent(); comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "ID"; LoadUsersToComboBox(); } PersonRepository peopleRepo = new PersonRepository(); private void LoadUsersToComboBox() { comboBox1.DataSource = peopleRepo.FindAllPeople().T...

I have some quite simple SQL that I can trying to change to either Linq or LLBLGEN

Hi All, I want to do something like this... SELECT DISTINCT T1.* FROM T1 INNER JOIN T2 ON T2.ID1 = T1.ID1 INNER JOIN T3 ON T3.ID2 = T2.ID2 --FOLLOWING CAN BE ADDED MULTIPLE TIMES (LOOPS IN C#?) INNER JOIN T2 AS T2A ON T3.ID2 = T2A.ID2 INNER JOIN T1 AS T1A ON T1A.ID1 = T2A.ID1 --END MULTI WHERE T1.ID1 = 1 AND T3.ID3 = 2 AND T3.ID4 = ...

What are the ways to perform these using LINQ?

Though I liked LINQ very much and using in our current project, sometimes we are facing problem to solve the following. Returning multiple results (tables) with single DB call from database and binding the same in ASP.NET. In case of stored procedures, using single SP we can perform multiple operations with single DB call. Using LINQ, ...

Linq: Convert IEnumerable<Point> to an IEnumerable<float>

I have an IEnumerable<Point> and I want to convert it to an IEnumerable<float>. Can I do this in a single Linq statement? IEnumerable<float> ConvertToPoints(IEnumerable<Point> points) { List<float> floats = new List<float>(); foreach(var point in points) { floats.Add(point.X); floats.Add(point.Y); } ...

How to represent this SQL query in LINQ to entities?

Hello I'm kind of new to LINQ and I'm trying to represent the following query in LINQ to Entities: Select * from Cotations CT1 where CT1.CotationID = iCot_ID and Revision = (select max(revision) from Cotations CT2 where CT1.CotationID = CT2.Cotation) where iCot_ID is an external parameter, and...