linq

how to use dynamic insert - linq to sql?

i want to use below codes. So i have a generic list<MyClass> i think that i should use using System.Reflection; method to get list<MyClass> property to fill string[] columnNames, object[] columnValues but how can i use it? foreach (var item in List<myClass>) { // i want to fill get columnNames and values to fill below array...

Inserting programmatically but i can not do that in linq?

How can i insert data programmatically? but i can not do that. No error return also no adding data in my database.How can i do that? i created a Extention method to use in my project look please below.i want to add extentionmethod but i can not. How can i add data with below extention method? namespace TestEng { public partial class...

Linq and SubSonic - returning nested complex types

Hi all, I'm new to SubSonic and reasonably new to LINQ as well, so I'm just trying to put a little app together. I've got the templates all sorted and running okay, but I've run into a bit of trouble with this LINQ statement (simplified slightly, the real statement has some other joins but they don't affect this particular problem so I'...

LINQ. Update one dictionary from corresponding values in another joined by key

I have to dictionaries dic1<double, double> dic2<double, double> The length might not match. So I need to update values in dic1 from dic2 joined by dic1.key == dic2.key... But preserve those values in dic1 which has no corresponding key in dic2. .NET is 3.5 ...

LinQ Data Row and Column collection C#

I have the row collection and the Column names as list , is there way to pass all the column names using the delegate to a single row and return the values as a collection?. or is there any other best way to accompolish this?. ...

How do you return certain properties from a linq query, rather than complete objects?

Hi all I've just downloaded the Linq provider for NHibernate and am just a little excited. But I don't know Linq syntax that well. I can return whole objects from a query like this: var query = from foo in session.Linq<Kctc.BusinessLayer.Domain.Case>() where foo.CaseNumber > 0 select foo; And I ca...

merging 2 collections and find all the unique items

Hi simple task I have 2 collections need to create a 3 one if you like by merging the 2 and giving me a third one with all the unique items only class Program { static void Main(string[] args) { ObservableCollection<Person> collectionA = new Observabl...

Use linq datasource to perform linq query and provide statistics about linq datasource

I have a gridview bound to a linq datasource and I would like to provide statistics about the gridview, such as you have 10 rows, 5 are of this type column and 5 are of this type, etc. Is there an easy way to get the linq query out of the linq datasource? I can access the where clause and the parameters, but I don't know how to transfor...

WPF LINQ and the ObservableCollection

Hi! In my WPF application I'd like to use LINQ as much as possible (expecially to avoid the "for each"). But WPF works a lot with the ObservableCollection, and I can't use LINQ with these kind of collection. How can I do? Thanks, Pileggi ...

C# CodeSmith LINQ to SQL question DELETE Operation

In a project I am working on I need to delete a "user" from my database. This "user" has two tables that reference it's foreign key. When hard deleting I am trying to delete all records from Table A and Table B that have foreign keys to the "user" and then deleting that "user" record. This is all done within repositories and using obj...

LINQ Query with Array input and variable Where Statements - Advice

I would like to query data given an array to filter by via WCF Data Services using the Silverlight Client API. Basically, I want to query Employees given a list (array) of States. I'm thinking something like this: public IQueryable<Employee> Load(string[] states) { foreach (var x in states) { // LINQ query here ...

"better" (simpler, faster, whatever) version of 'distinct by delegate'?

I hate posting this since it's somewhat subjective, but it feels like there's a better method to do this that I'm just not thinking of. Sometimes I want to 'distinct' a collection by certain columns/properties but without throwing away other columns (yes, this does lose information, as it becomes arbitrary which values of those other co...

If Linq Result Is Empty

If I have a linq query that looks like this, how can I check to see if there were no results found by the query? var LinqResult = from a in Db.Table where a.Value0 == "ninja" group a by a.Value1 into b select new { Table = b}; if(LinqResult.Count() == 0) //? { } ...

Reusing Expression in Linq select clause (query format)

I have an Expression that converts one type of object to another type. The expression is as follows: public Expression<Func<SQLRepository.ActionType, Model.ActionType>> DBActionTypeToActionType = (SQLRepository.ActionType at) => new Model.ActionType() { ID = at.OID, DisplayName = at.DisplayName }; I can use the Expression like...

Using LINQ to find all keys from one collection that are not in another?

Hey all, I'm trying to locate all the keys in one Dictionary that are not in another Dictionary. Obviously, I can do this using a nested loop, but I'm trying to learn LINQ at the moment and I was wondering if I might use it to accomplish this task? Here's what I have so far: Dictionary<string, List<string>> DBtables = this.CollectTab...

DBMetal (SQLite): "Sequence contains more than one element" with multiple foreign keys

When trying to create a C# file using DbMetal (as part of DbLinq), I get the following error: DbMetal: Sequence contains more than one element It's only appearing when I reference multiple foreign keys as part of my primary key. The following is the DDL for my table causing issues: CREATE TABLE [QuestionChoice] ( [Questionair...

Trouble putting Statement Lambda inside a LINQ query

I'm trying to inject some inline work as a Statement Lambda into a LINQ query select like so... // NOTE: mcontext.Gettype() == System.Data.Linq.DataContext // Okay - compiles, nothing unusual var qPeople1 = from ME.tblPeople person in mcontext.tblPeoples select person; // ERROR - see below compile Error - Can I retrofit ...

Serialize a list<string> and use each string as xml Node

I've ran into a problem and wondered if there's simple way of solving it. Here I have a XML template, defining some properties and their values. <Properties> <Property name="ID">10000</Property> <Property name="Name"> <SubProperty name="FirstName">Foo</SubProperty> <SubProperty name="LastName">Bar</SubProperty > </Propert...

ASP.NET MVC2 Linq Where Clause using StartsWith

I have a few filters on my view, the first one is list by first name, last name and company name when one of these options are selected the user can then select a, b, c ... x, y, z to show only people starting with the selected letter. if (collection["Filter"] == "2") { presentations = presentations.Where(x => x.Person.FirstName.Sta...

Generate LINQ DataContext from XML, XSD, or C# class

Hi, I have a massive set of classes I need to create from an XML file that I'd really not like to do by hand. What I'd really like to do is somehow generate a LINQ DataContext so I can use VisualStudio to build a SQL database from the DataContext. I'm aware that I can generate XSD and C# classes from the XML file, but are there any tool...