linq

Display SQL Server table in DataGridView

I think it's kind of noob question but I'm new to SQL Server in .NET and I've already lost several hours on this... I started new project, inserted DataGridView on empty form and as Data Source I chose Add->Database and I created new SQL Server Database File. I called it db.mdf. Now I get DataSet named dbDataset and BindingSource named ...

How to get unique entries of products in a List<Order> with LINQ

I have a classic Order -> Order Row scenario something like this: public class Order { public int Id { get; set; } public string Name { get; set; } public List<OrderRow> OrderRows { get; set; } } public class OrderRow { public int Id { get; set; } public int ProductId { get; set; } public int Amount { get; set;...

Sort child objects while selecting the parent using LINQ-to-Entities

Imagine you've got some Entity Framework entities that look like this (obviously not these specific classes, but the autogenerated ones with all the Entity Framework plumbing; these are just for illustration): public class Parent { public int ID { get; set; } public List<Child> Children { get; set; } } public class Child { ...

Conditional shortcuts in LinqToSql query

Here's a little LinqToSql GOTCHA: // Returns the number of counties in a state, // or all counties in the USA if the state is null public static int CountCounties(State s) { var q = from cy in County.GetTable() // my method to get the ITable where (s == null || s.Code == cy.StateCode) // shortcut OR operator, right...? s...

Confusion over storing a type in a temp variable in a LINQ query

Hi, I am writing a LINQ query which has a sort of subquery. It looks like this: var x = from p in pc let Cntrs = p.GetCounters().Where(args => args.CounterName == CounterName) select Cntrs; Cntrs is a PerformanceCounter object. However, the intellisense returns it as a collection with collectio...

LINQ query expression translator?

I'm adding a LINQ interface to some custom objects, but the C# compiler fails on type inference. However, I can write the equivalent query using the raw extension methods and type inference succeeds, so I'm not sure how the compiler is translating the query expression into extension method calls. Is there a tool or compiler flag so I ca...

ORM for GSQL, LINQ 2 GSQL ?

is there LINQ 2 GSQL implementation ? Note : GSQL is the query language (SQL subset) used in Google AppEngine datastore ...

Generic method using linq expressions

Hello, i have the next 2 methods public static string[] Method1(CustomObj co) { return new string[] {co.X,co.Y }; } public static string[][] Method2(IQueryable<CustomObj> cos) { string[][] s = new string[cos.Count()][]; int i = 0; foreach (var co in...

Is it possible to use Linq-SQL without drag-and-drop?

If i want to use Linq-SQL i also have to drag the DB Table unto the designer surface to create the entity classes. I always like full control in my application and do not like the classes created by dotnet. Is it possible to provide this connection between Linq and the DB using my own Data Access Layer Entity classes? How can i get i...

Dynamic grouping

I have a datatable like below, the Sales team can have any numbers (in the below example only two columns sales1and sales2) FactoryName MachineName StartTime Sales1 Sales2 Fact 1 M1 2009-11-06T00:00:00+05:30 1 2 Fact 1 M2 2009-11-06T00:00:00+05:30 1 2 Fact 2 M1 2009-...

Generic Database Linq

Given a function as below, i can take a single table from my database and write a lambda using the Where extension method and pretty much build all the other cases using a simple wrapper method and supplying a filter. public void getPeople(Expression<Func<tblPeople, bool>> filter, Action<List<tblPeople>> callback) { ...

Linq Return Filtered Children

I'm having a 'duh' moment where this seems like it should be straight forward, but I can't seem to get it right. I have a simple collection: Category Name ---> List<Category> (Children of this category) I want the user to be able to filter based on Category.Name while maintaining the hierarchy. So for example. My Category ---...

Linq to XML when data held in a list

I have a list of strings that I need to use to create the following XML. The items in the list are strings "Line 1", "Line 2" etc. The tricky bit is that the element names increment from "l1" upwards. Is it possible to use Linq to do this or should I use a different approach ? <srv> <enqRsp> <l1>LINE 1</l1> <l2>LINE 2</l2> ...

linq GroupBy with Where

I have entries in table codelistvalueview of this type: I want to group by namespace and maybe then by tablename and find out all the entries that only occur in both the namespaces (UPD/REFDAT) and then list then ones that occur in UDP so they can be deleted. namespace tableid tablename count UDP 1C06F2EF-5371-4A3F-A07C-226DB7242053 We...

How do I join on a constant in LINQ?

I'm trying to do a left join on a constant like this: SELECT [t0].[DeviceId], [t0].[DeviceTypeId], [t0].[UnitId], [t0].[UnitNum], [t0].[ManPhone], [t0].[Status], [t2].[MaintDate] AS [ServiceExpiration] FROM [dbo].[Devices] AS [t0] INNER JOIN [dbo].[CustomerDevices] AS [t1] ON ([t0].[DeviceId]...

need to remove a column from a table in a Linq project

I have extensive experience working in ASP.NET and Sql Server but I am new to Linq. I have just inherited a project that was created using Linq. Unfortunately the last developer knew nothing of efficiency and was storing images in the database in a truly terrible way. I have modified the code so that it no longer uses the column that st...

Time Stamp in DBML is solving concurrency issues...why?

We use LINQ in our ASP .NET application to run database queries and commands. We have been having concurrency issues on updates to tables in which we update the value of a Date field. More specifically, if two users click a button at the exact same time and the code attempts to update a Date field in the database then the built-in optim...

List of Interfaces vs. List of Derived Type - Cannot Convert Expression Type to Return Type

Why does this work: public IList<ICoupon> GetCouponsForSite(string siteSlug) { var coupons = _db.Coupons.Where(x => x.Site.slug == siteSlug) .Select(x => new Coupon(x.id)); var list = new List<ICoupon>(); foreach (var coupon in coupons) { list.Add(coupon); } return list; } But thi...

IronRuby references conflict with System.Linq ?

Using Visual Studio 2010, when I add the four IronRuby references to an existing project that uses Linq in several methods, the project won't compile due to not being able to find System.Linq all of a sudden. Does the IronRuby/.Net 4.0 Framework change the location of Linq or am I missing something? Thanks, Becky ...

How can I make this LINQ search method handle more than two terms?

The following search method works fine for up to two terms. How can I make it dynamic so that it is able to handle any number of search terms? using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestContains82343 { class Program { static void Main(string[] args) { ...