linq

LINQtoXSD Adding attribute to generated classes

I'm trying to render the contents of a generated LinqToXsd class into a custom system.Windows.forms.Propertygrid I've created the converter class by inheriting system.Componentmodel.ExpandableObjectConverter and all is well there. My problem is trying to apply the TypeConverterAttribute to the LinqToXsd generated class as this gets reg...

How to "EnforceConstraints" to avoid linq errors?

Hello, I'm working on a sample from the book I bought. And, for unknown reason, I get the following error message " Could not find an implementation of the query pattern for source type 'System.Type'. 'Where' not found." The VS2008 help says that I need to add System.Linq and System.Collections namespaces to solve the issue. Unfortun...

ado.net data services - how to grab subsets of data from the data model?

Hi, Im starting to use ado.net data services in a little silverlight application that Im putting together. Currently I'm using it in the most simplistic was possible: var teams = (from t in ents.tblTeams select t) as DataServiceQuery<tblTeams>; teams.BeginExecute( (ar) => this.cmTeams...

Linq - customized column

select ID, 0 as Index from Table; How do I do this query in linq? var o = From X in Table Select X.ID, (0 as Index) <- error ...

Defining a one-to-one relationship in SQL Server

I need to define a one-to-one relationship, and can't seem to find the proper way of doing it in SQL Server. Why a one-to-one relationship you ask? I am using WCF as a DAL (Linq) and I have a table containing a BLOB column. The BLOB hardly ever changes and it would be a waste of bandwidth to transfer it across every time a query is ma...

Incrementing an element using LINQ to XML

Using VB.NET (3.5), i have an ArrayList of Employees. I'm trying to build an XML representation (to feed another system) and one of the fields is a simple incrementing ID, starting at 1. The code I currently have is: Dim Emps = <Employees> <%= From ee As Employee In Employees _ Select <Employe...

Convert this SQL to LINQ

How do I do this query in linq? All the tables already are list of objects. This query give points to entities named "Empresas" (Companies) that fills the "Palavras" (Words) criterias. select x.empresaid, sum(x.pontos) from ( select a.empresaid, sum(1) as Pontos from empresa a inner join Palavras b on a.nome like '...

Some example how use storage procedure (add, edi, del) in MVC .NET application +LINQ

I look for some exaple how use the stora procedurs in MVC with LINKQ. ...

Compare only Date in nhibernate linq on a DateTime value

Hello, I trying to compare two dates (DateTime) in nhibernate linq: query = query.Where(l => (l.datCriacao.Date == dtLote.Date) but the error: NHibernate.QueryException: could not resolve property: datCriacao.Date of: SAGP.Entities.Lote anyone knows how I can solve this? tks ...

Problems with Linq using anonymous type

Why did the anonymous type property "Points" still have the value "0"? Public Class Test Public Sub New(ByVal _ID As Integer) ID = _ID End Sub Public ID As Integer End Class Dim list As New List(Of Test) list.Add(New Test(1)) list.Add(New Test(2)) list.Add(New Test(3)) Dim query = From X In list Select New With {....

How to merge multiple ControlCollections in C#?

Is there an elegant way of doing this? Perhaps with Linq? For something like this: List<ControlCollection> list = { ... } List<Control> merged = list.MergeAll(); EDIT: The final collection will be single dimensional in a sense that all controls will be there, not in a nested way. ...

Why is ToLookup() dependent on load options in Linq2Sql?

Lets say I have 3 tables Posts, PostTags and Tags defining a many-to-many relationship. I want to get a lookup table that will give me all the Posts related to a given tag so I use the following code: return dataContext.PostTags.ToLookup(pt => pt.Tag, pt => pt.Post); In unit test all went fine but in the real application, it didn't wo...

Linqy no matchy.

Hi All Maybe it's something I'm doing wrong. I'm just learning Linq because I'm bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. usage: enter text into textbox, click button. program lets you select a file to match the textbox value against and returns matches ...

Linq Lookup dynamic list

Hi, I have a List of objects (string filename, BitmapImage image) to use as a cache of images. private static readonly List<ImageData> imageCache = new List<ImageData>(); I created a Lookup to check this cache for an image each time it is required. If the image is not in the list it is added to the list. The Looked is statically cre...

Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique?

I have a List<> of custom objects. This custom type has a property called Name which should be unique among the list. In other words, no 2 items items in the list should have the same value for their Name property. When I validate this list, I want to retrieve the offending items. Is there a Linq operation which will allow me to do thi...

Linq operations against a List of Hashtables?

I'm working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/hashtables: Hashtable1: Key:Column15, Value:"Jack" Key:Column16, Value:"Stevens" Key:Column18, Value:"7/23/1973" Key:Column25, Value:"Act...

linq query for tag system - search for multiple tags

Hi I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have the tag asp.net AND jquery as i said, the amount of tags to look for is generic how can i do something like that? thx update 17.11.20...

IEnumerable to array of parameter

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word.Elements("id")) { idList.Add(idElement.Value); } string[] ids = idList.ToArray(); It would be similar to this But I need the XElement.Value paramete...

how to write linq query based on EF?

Suppose I have three tables: Person(pid, ...) PersonAddress(pid, aid,...) Address(aid, ...) Then I want to get the person address like sql: select a.* from address a join PersonAddress pa on a.addressID=pa.addressID where pa.personID = myPersonID Use Entity Framework to create Entity model, then want to write a linq equivalent as ...

linq paging - get total rows

Hi, i have a question about linq. I'm using Skip and Take to do paging: (from l in db.ProductList select l).Skip((page - 1) * row_per_page).Take(row_per_page) It work, and i need retrieve total rows of product list to calculate max page. I think i must use another query to count rows but have another way to do this in one qu...