linq

How do I map view columns in Linq to Sql to related objects similar to foreign key behavior?

I have a view that returns ID columns that I want linq to sql to expand automatically. Is this possible? (It needs to translate to sql) I tried decorating my partial class with an Association attribute but this seems to fail internal mapping validation. Then I tried creating associations in the designer but that didn't seem to generate ...

How do I get the highest currently used ID number in a table with LINQ?

I have a table with a list of names. This table has an ID column that is an autoincremented number. I would like to display on my website something like, "6,523,213 names created so far." So, I need to get the highest currently index/ID number from my names table. I can think of a few ways to do it, I could OrderBy ID by desc and se...

Does the way you write sql queries affect performance?

say i have a table Id int Region int Name nvarchar select * from table1 where region = 1 and name = 'test' select * from table1 where name = 'test' and region = 1 will there be a difference in performance? assume no indexes is it the same with LINQ? ...

How can I query the range of date which one product has not been ordered? (LINQ)

I have three tables, Products(ProductID, ProductName) Orders(OrderID, OrderDate) OrderDetails(ProductID, OrderID) Junction table between Products and Orders. For example, there are Three ProductID in Products table A01, A02, A03 Four OrderID in Orders table 1. 01/01/2009, 2. 03/01/2009, 3. 05/01/2009, 4. 07/01/2009. OrderDetails d...

Problem with paging with Linq and DataTable

Hi, I'm writing a small web app in VB.NET and I would like to do paging for my DataTable in the following function : Public Shared Function Testing(ByVal KeyWord As String, ByVal CurrentPage As Integer, ByVal PageSize As Integer) As DataTable Dim db As New BibleDataClassesDataContext Dim dtDataTableOne = New DataTable...

If I fill a GridView with anonymous objects, how can i get their properties?

Hi, I have a GridView what I fill through a LINQ expression. Something like this: GridView1.DataSource = from c in customers, o in c.Orders, total = o.Total where total >= 2000 select new {id = c.CustomerID, order = o.OrderID, total = total}; And in its RowCreated method I try to get a property, for example the id, but it has no...

Standalone WPF Filter Control

Most WPF data grid controls around have an inbuilt ability to filter the data shown. I am interested in using that functionality, but disconnect from data grid usage. I'm hoping to find a user control that will return an Expression<Func<T, bool>> that I can use in a LINQ query. Does anyone know of such a user control? ...

refactoring LINQ IQueryable expression to remove duplicated portions of queries

I have some linq queries that have redundancy I'd like to factor out a single piece of code. These are join experssions that are IQueryable, and its important I don't cause the query to be evaluated earlier than it would be without the refactoring. Here is a simplified query: var result = from T in db.Transactions join O in db.Orders...

What's a clean way to break up a DataTable into chunks of a fixed size with Linq?

Update: Here's a similar question Suppose I have a DataTable with a few thousand DataRows in it. I'd like to break up the table into chunks of smaller rows for processing. I thought C#3's improved ability to work with data might help. This is the skeleton I have so far: DataTable Table = GetTonsOfData(); // Chunks should be any ...

Linq: How to Assign to Related Entities ?

How do I assign to an entity's related objects in a simple way? properties=IList<property> linq Entities: People People.Properties To assign properties list to People.Properties, some properties may be new and others may already exist. How do I assign each property to the People.Property in a simple way? ...

How does linq determine value changes?

If the value of a field is not actually changed but reassigned the same value, will that reassignment be marked for update when submitting to database? ...

Mapping Linq Entities and Domain Objects and object tracking

If I map my Domain objects to linq Entities will I now not be able to track changes when saving my domain objects? So for any change in my model that i wish to make, once I map the object to linq entities for submission to db, all object values will be submitted to the db by linq since it it goes through a mapping first? Or would the obj...

Selecting a single item with linq2sql query

Hey everyone, I'm trying to retrieve a single entity from a Linq2Sql query, but I'm having trouble finding the 'pretty' way of doing it. Here's what I've found that works: var states = from state in dc.States where state.Id == j.StateId select state; State s = states.ToList<State>().ToList()[0]; I'm hoping this isn't the best way o...

Linq over DataTable with .Skip() and .Take() method

Hi, I have this function that returns a DataTable : Public Shared Function GetDataTable(ByVal PageSize As Integer, ByVal CurrentPagea As Integer) As DataTable Dim dtData As New DataTable dtData = da_Book_Content.GetDataContent() 'TODO : how to do data paging for dtData with Linq Return dtData End Function On a pa...

Linq to Objects - Where search within a list

Linq to Objects - Where search within a list internal class ProdQtyByWarehouse { public int id { get; set; } public List<ProdWarehouseQty> ProdWarehouseQtys { get; set; } } internal class ProdWarehouseQty { public int id { get; set; } public string PName { get; set; } } prote...

The || (or) Operator in Linq with C#

Hi, I'm using linq to filter a selection of MessageItems. The method I've written accepts a bunch of parameters that might be null. If they are null, the critea for the file should be ignored. If it is not null, use it to filter the results. It's my understanding that when doing an || operation is C#, if the first expression is true, t...

Is LINQ slower than calling stored procedures?

I'm hoping that we will be overhauling our system to use ASP.NET MVC, however all of the examples provided tend to use LINQ to SQL. We were told by a LINQ developer than it is actually slower than calling a store procedure. Furthermore, how would you call a stored procedure for output using MVC? I'm not entirely sure LINQ would meet o...

Stored Procedure Multiple-Table Output With LINQ and ASP.NET MVC

Quite often our systems call stored procedures which output multiple tables worth of results. Previously we used XML outputs to get each table and relate them correctly using XSLT. If I were using ASP.NET MVC with LINQ calling a stored procedure, how do I get each of the tables and then output the data as necessary? ...

Paging Support - ADO.NET Entitry Framework and LINQ

What kind of paging support is offered through ADO.NET EF and LINQ? What does a "first 10" Select look-like? A "next 10" Select? ...

Combination Generator in Linq

Hi, Is it possible to create some Linq that generates a List containing all possible combinations of a series of numbers?? If you enter "21" it would generate a list with the elements: list[0] = "21" list[1] = "22" list[2] = "11" list[3] = "12" (Not nessesarily in that order) I understand you can use range to do things like: List<...