linq

query xmlnode using linq

I have following file: <root> <Product desc="Household"> <Product1 desc="Cheap"> <Producta desc="Cheap Item 1" category="Cooking" /> <Productb desc="Cheap Item 2" category="Gardening" /> </Product1> <Product2 desc="Costly"> <Producta desc="Costly Item 1" category="Decoration"/> <Productb des...

linq to entities generated sql

I am having some problems with linq to entities in the ado.net entity framework. Basically what I'm doing is this: var results = (from c in companies where c.Name.StartsWith(letter) select c); and this gets translated to SQL as something like: WHERE (CAST(CHARINDEX(@p, [Extent1].[Name]) AS int)) = 1 which is fine but my table has...

problem in gridview with LINQ

Hi all, when i am trying to display result in gridview using LINQ i am getting this error message."Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition." i am not getting any clue what to do? Here is my code protected void SelectBtn_Click(object sender, EventArgs e) { ShowEmployee(); } private void Sh...

Issues Doing a String Comparison in LINQ

Hello All, I'm having trouble getting LINQ to translate something into the query I need. In T-SQL, we do a <= and >= comparison on three columns that are CHAR(6) columns. LINQ will not allow me to do this since Operator '<=' cannot be applied to operands of type 'string' to 'string'. I have the following T-SQL query.. SELECT ...

Nested Linq crashes intellisense

Currently I'm using Visual Studio 2008 (SP1) and developing some code that uses nested LINQ statements. How ever with every level of nesting the intellisense performance drops considerably to the point where it become unusable. Has anyone else experienced something similar or found a solution to this problem? Cheers for any help Tony ...

Can I get specific metadata from a Func<T, object>?

Consider the following code: string propertyName; var dateList = new List<DateTime>() { DateTime.Now }; propertyName = dateList.GetPropertyName(dateTimeObject => dateTimeObject.Hour); // I want the propertyName variable to now contain the string "Hour" Here is the extension method: public static string GetPropertyName<T>(this IList<...

Creating KML with Linq to XML

About 9 months ago, I created a set of classes in C# that correspond to KML 2.2 elements. So you can do things like myPlacemark = new Placemark("name"); Internally, it uses XmlDocument, XmlElement, etc. to create the various nodes and tags. It's a memory pig and it could probably be faster. No, I didn't generate the classes using XS...

How to change LINQ O/R-M table name/source during runtime?

I've got a database, and an entityset created by the O/R-Mapper, using all this with LINQ. In the O/R-Mapper I need to enter a table name (source) for every table, which is being used for the SQL generated by LINQ. In the .dbml file it looks like this: <Table Name="dbo.Customers" Member="Customers"> Now I'd like to change this table ...

To Linq or not to Linq - which version is prettier?

I just wrote the following function: public string Ebnf { get { var props = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); var ruleProps = from p in props where p.PropertyType.IsSubclassOf(typeof(ARule)) select p; var rules = from p in ruleProps select (ARule)p.GetValue(this, null); ...

A DSL for Linq Queries - looking for ideas

I am currently using a CMS which uses an ORM with its own bespoke query language (i.e. with select/where/orderby like statements). I refer to this mini-language as a DSL, but I might have the terminology wrong. We are writing controls for this CMS, but I would prefer not to couple the controls to the CMS, because we have some doubts abo...

LINQ Query to insert data into the database.

Hi all, In my database, I have a table named Students, with 3 Columns (SNo, SName, Class). I want to insert the value of only SName. Can anybody tell me how to write the LINQ Query for this. Thanks, Bharath. ...

Loading relations in linq2entities automatically

When i have a relation between two entities in my model: [GroupMember] (*) ----- (1) [User] and tries to select items from this relation with LINQ: From entity in _user.GroupMember select entity I always get an empty result unless I load the relation first with following statement: _user.GroupMember.Load() Is there a way to avoid l...

Can I rewrite this more elegantly using LINQ?

I have a double[][] that I want to convert to a CSV string format (i.e. each row in a line, and row elements separated by commas). I wrote it like this: public static string ToCSV(double[][] array) { return String.Join(Environment.NewLine, Array.ConvertAll(array, row => ...

How to remap properties in LINQ?

I am getting a list of running processes via LINQ. The two properties I want are "ProcessName" and "WorkingSet64". However, in my UI, I want these properties to be called "ProcessName" and "ProcessId". How can I remap the name "WorkingSet64" to "ProcessId"? I did a pseudo syntax of what I am looking for below: using System.Linq; usi...

What is the quickest way to query a database with LINQ?

I'm reading a WROX book on LINQ and the author is performing LINQ on a database. Essentially he is accessing the database as an object as shown in the code below. But I don't see how he expects to "access the database as an object", even the downloaded code gets an error on "db.DirectoryInformation" saying "DirectoryInformation" is unkn...

From "LINQ to SQL" to "Azure Table Storage" or "SQL Data Service"

I have a Silverlight application where I use LINQ to SQL to store my data. Now I have added this application to an Azure cloud, and want to use an Azure method to store my data. But I don't know whether I should use "Azure Table Storage" or "SQL Data Service", and how I can use it. ...

Is it wise to use LINQ to replace loops?

Now that we have tremendous functionality thanks to LINQ, I'm wondering which syntax is preferable. For example, I found the following method (just thought it was a good example): foreach (FixtureImageServicesData image in _fixture.Images) { if (image.Filename != _selectedFixtureImage.Filename && image.IsPrimary) { image...

Linq query with aggregates

I want to write an elegant linq query to handle the following SAMPLE object model: class Category { public string Name { get; set; } public IList<Product> Products { get; set;} } class Product { public string Title { get; set; } public IList<Photo> Photos { get; set; }...

Convert to Lambda expression

I have the following expression var q = from c in D1 join dp in (from e in E1 group e by e.ID into g select new { ID = g.Key, Cnt = g.Count() }) on c.ID equals dp.ID into dpp from v in dpp.DefaultIfEmpt...

How to put   in text when using XElement.

I'm using the new System.Xml.Linq to create HTML documents (Yes, I know about HtmlDocument, but much prefer the XDocument/XElement classes). I'm having a problem inserting &nbsp; (or any other HTML entity). What I've tried already: Just putting text in directly doesn't work because the & gets turned int &. new XElement("h1", "Text&nb...