linq

Find a combination of two elements that have not been viewed together (LINQ, SQL or C#)

Hi, I have a page that displays two objects and then the user picks one of these. I record the preference and the combination in a MSSQL database and end up storing data like this: UserId=1, BetterObjectId=1, WorseObjectId=2 Now I would like to avoid showing that combination of objects (1,2 / 2,1) ever again. So how do I generate ra...

i4o vs. PLINQ

I have a question for anyone who has experience on i4o or PLINQ. I have a big object collection (about 400K ) needed to query. The logic is very simple and straightforward. For example, there has a collection of Person objects, I need to find the persons matched with same firstName, lastName, datebirth, or the first initial of FirstName/...

How do I add a record to a database with LINQ?

I have been utilizing Scott Gu's tutorials on LINQ to SQL to try to learn some LINQ. I have been able to view, retrieve, and update records but I am unable to write new records into the database (MSSQL). Scott starts getting into inserting rows in the fourth section of the set of tutorials. As you can see on that page (or may already kn...

Populating child collection property with LINQ sub-query

I'm fairly new to LINQ in general but I've managed to figure things out so far to get the result I want/need. The LINQ2SQL query below produces the desired results in which there are Location objects, each with their own collection of Units. The initial variable declarations are done to setup the values that I need to query from and shou...

Using Linq to map facebook profile with my user info

After reading a book on LINQ I'm thinking about re-writing a mapper class that I wrote in c# to use LINQ. I'm wondering if anyone can give me a hand. Note: its a bit confusing, but the User object is the local user and user (lowercase) is the object generated from the Facebook XSD. Original Mapper public class FacebookMapper : IMappe...

Getting 'Data source is an invalid type' when binding Linq query to Gridview

Hi all - I'm trying to bind a gridview to a linq to sql query that's using a stored procedure. When I run the page, i get the following error: Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource. var db = new TableItemDataContext(); var q = db.sp_SearchForItems("1","2","3","4"); GridView1.D...

How to create LINQ Expression Tree with anonymous type in it

I would like to generate the following select statement dynamically using expression trees: var v = from c in Countries where c.City == "London" select new {c.Name, c.Population}; I have worked out how to generate var v = from c in Countries where c.City == "London" select new {c.Name}; but I cannot ...

Converting SQL containing top, count, group and order to LINQ (2 Entities)

Some LINQ queries still puzzle me. for a table 'Hits' containing two columns, 'Page' and 'Date', I want to find the most Pages with the most rows in a defined slice of time. In SQL I would use this: SELECT TOP 10 [Page] ,COUNT([Page]) as Number FROM dbo.[Hits] WHERE [Date] >= CONVERT(datetime,'14 Jan 2009') AND [Date] < CO...

How do I find a subset of items in two sets of data that partially differ?

I am trying to get the subset of items in dataA that are in dataB, and have different values of property c. The properties a and b can be used as an index, so I have tried to filter out only the useful pairs then check to see if they have a different c value. This is the linq expression I came up with, and it does work, but It seems li...

getting nested results from linq to sql

my data looks like this in the table: ID Name Parent ID --- ---- --------- 1 Mike null 2 Steve 1 3 George null 4 Jim 1 I can't figure out how to write a linq to sql query that will return the results with the parent rows grouped with their child rows. So for example this is the result I...

How do I find an XML element by attribute using LINQ to XML?

I'm learning LINQ to XML and need to find the existence of an element with a particular attribute. At the moment I'm using: XElement groupCollectionXml = XElement.Parse(groupCollection.Xml); IEnumerable<XElement> groupFind = from vw in groupCollectionXml.Elements("Group") where (string) vw.Attribute("Name") == groupName sele...

linq Order By for a List(Of myObjects)

How do I order by a passed string value on my list of objects? i need to do paging and sorting on my List(Of) objects the paging is no problem but I don;t know who to get the Order By to work. Here is what I am currently doing and it's working great: Return returnReports.Skip(PageSize * (PageNumber-1)).Take(PageSize).ToList() How do ...

.net Databinding - Referencing Anonymous Type Properties

I have bound an ASP.net GridView to a collection of anonymous types. How can I reference one of the properties of the anonymous types in the RowDataBound event handler? I am already aware of the way to cast the anonymous type like this: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowTyp...

LINQ using C#.net

Can any one guide me to learn LINQ in C#.net i am new to this concept ...

DropDownList SelectedIndex value not updating on AutoPostback

It looks like this question was addressed here, but his solution did not work for me. I am creating a dynamic dropdown menu system that populates a secondary dropdownlist with the results of a query based on the selected item in the first dropdown. First dropdown getting populated: Dim db As New linqclassesDataContext Dim categories =...

Is it possible to change &amp; to & in the results from a LINQ query?

I have the following code: Dim db As New linqclassesDataContext Dim categories = (From c In db.faq_cats) NewFaqDropDownCategory.DataSource = categories NewFaqDropDownCategory.DataTextField = "category" NewFaqDropDownCategory.DataValueField = "category_id" If Not Page.IsPostBack Then NewFaqDropDownCategory.DataBind() End If Unset(cat...

How can I query two databases and combine the results using LINQ?

I need to pull values in similar tables from two different databases, combine them and then write the output to a CSV file. Can I just create a second connection string in the Properties file and explicitly pass the DataContext the second connection string for the other LINQ query? Or do I need to do something else? The tables are nea...

LINQ Query for Controlling some item.

Hi, I have got a windows forms project. c# . For example there are 2 textbox in my form. In first textbox for Name and second is for surname.; Whenever user press over TAB button i wanna check from Database if there is a name like my first textbox's.text.If there is than it will get next control if it is not. then my program will ask fo...

How to make a return type for a result set in LINQ

I am having a problem determining how c# and LINQ solve the common problem of handling a data structure that does not necessarily return a table structure, but instead a resultset. I have a stored procedure that works, and have included it in my DBML [Function(Name="dbo.p_GetObject")] public int p_GetObject([Parameter(Name="ObjectType"...

Linq To Entity Framework selecting whole tables

I have the following Linq statement: (from order in Orders.AsEnumerable() join component in Components.AsEnumerable() on order.ORDER_ID equals component.ORDER_ID join detail in Detailss.AsEnumerable() on component.RESULT_ID equals detail.RESULT_ID where orderRestrict.ORDER_MNEMONIC == "MyOrderText" select new { ...