linq

Help required to optimize LINQ query

I am looking to optimize my LINQ query because although it works right, the SQL it generates is convoluted and inefficient... Basically, I am looking to select customers (as CustomerDisplay objects) who ordered the required product (reqdProdId), and are registered with a credit card number (stored as a row in RegisteredCustomer table wi...

Can I achieve this with linq instead of For Each?

Dim customers As List(Of Customer) = New List(Of Customer) For Each mbi In fordContracts customers.Add(mbi.Customer) Next Is it possible to query fordContracts for customers? It is an IList(of mbi) and each mbi object has an EntityRef to a Customer object. I just wanted to know if there was a better way to achieve this...

LINQ to XML + left join + group by = fail

I have two tables: block: int id, [other columns...] blockInstance: int id, int blockId (references Block.Id), [other columns...] My goal is to generate an enumeration of block objects with two properties: (1) Id (the Id of the Block) and (2) InstanceCount (the number of Instances for the Block). Currently, my XML file contains no Blo...

Wrap text in xml into element tags in Linq to Xml

I need to wrap up all the text thats in a large XElement tree, into Elements. For example: <element1>hello<element2>there</element2>my friend</element1> Becomes <element1><text value=”hello”/><element2><text value=”there”/></element2><text value=”my friend”/></element1> ...

Using LINQ to Get Sum/ Average of a List with custom objects

I have a class: public class PointD { public double X { get; set; } public double Y { get; set; } public PointD(double x, double y) { X = x; Y=y; } //operator for +,-, * and / are overridden } Given a list<PointD>, how to get the average of it using LINQ? A for loop equivalent will be s...

Obtain the Index of the Maximum Element

Given such a list: List<int> intList = new List<int>(); intList.Add(5); intList.Add(10); intList.Add(15); intList.Add(46); How to obtain the index of the maximum element in the list? In this case, it's 3. This should be an easy question, but I don't know why I can get this out. Edit: It's a s...

Reproduce a "DELETE NOT IN" SQL Statement via LINQ/Subsonic

I want to do something like DELETE FROM TABLE WHERE ID NOT IN (1,2,3) AND PAGEID = 9 I have a List of IDS but that could be changed if needs be. I can't work out how to get a boolean result for the LINQ parser. Here is what Subsonic expects I think. db.Delete(content => content.PageID == ID).Execute(); I can't work out how to do the ...

Query simple XDocument in LINQ

I'm probably doing something realy stupid but I cant get this to work: var xmlQuery = from i in doc.Descendants("Item") select new TriggerItem() { CreatedDate = DateTime.Now, ItemIdentifier = i.Attribute("itemCode").Value, Name = i.Attribute("name").Value, ProductIdentifier = (i.Attribute("productCode") != null) ? i.Attribut...

How to do an "in" query in entity framework?

How can I do a select in linq to entities to select rows with keys from a list? Something like this: var orderKeys = new int[] { 1, 12, 306, 284, 50047}; var orders = (from order in context.Orders where (order.Key in orderKeys) select order).ToList(); Assert.AreEqual(orderKeys.Count, orders.Count); I tri...

.NET List.Distinct

I'm using .NET 3.5. Why am I still be getting: does not contain a definition for 'Distinct' with this code: using System.Collections.Generic; //.. . . . . code List<string> Words = new List<string>(); // many strings added here . . . Words = Words.Distinct().ToList(); ...

Linq Newbie. Can I write this Linq query more concise?

Dim entName = "Some Auto Dealer" Dim whereEntity As Expression(Of Func(Of Entity, Boolean)) = Function(en) en.ENTY_Name = entName Dim login = Repository(Of Entity).Create().FindSingle(whereEntity) Dim whereDealer As Expression(Of Func(Of Dealer, Boolean)) = Function(dlr) dlr.Entity.Equals(login) Dim dealer = Repository(...

Converting log files to XML and (X)HTML, recommendedations

I've been tasked with converting some text log files from a test reporting tool that I've inherited. The tool is a compiled C# (.NET 3.5) application. I want to parse and convert a group of logically connected log files to a single XML report file, which is not a problem. The System.Xml classes are easy enough to use. However, I also w...

Compiling a Delegate with Expression.Lambda() - Parameter Out Of Scope, but is it really?

...

Entity-Framework -> MySql gives 'Function evaluation timed out.'

I having a weird problem with Entity Framework with MySql database. Here's the code that I've got. public class testbase { private testEntities db = new testEntities(); public IQueryable<post> GetRecords() { return db.record; } } Here record is a table in my database and this could should return all the rows ...

Using ASP.NET WebService with javascript

Hi evrery one! I have this code in my project: var UI = { Layouts: { ShowLayoutSettings: function(pid, lid) { My.PageServices.GetPageLayout(lid, pid, UI.Layouts._onShowLayoutSettings); }, _onShowLayoutSettings: function(obj) { alert(obj.ID); } } } and in my asp.net project a web service named PageSer...

What are the best blogs for staying up to date on C#, ASP.NET, LINQ, SQL, C++, Ruby, Java, Python?

Apologies if this repeats another - but I couldn't fine one like it. My day to day programming spans a fair number of technologies: C#, ASP.NET, LINQ / SQL, C++, Ruby, Java, Python in approximately that order. It's a struggle to keep up to date on any of best practices, new ideas, innovation and improvements, let alone all. Therefore,...

Updating relationships using Dynamic Data in Asp.Net

Hello guys, I'm trying to write a simple blog post/tag example using dynamic data and a linq data source. I wrote a simple database to store blog posts (title, text) and tags (only a word field and the foreign key) in a sinple one to many relationship and I'd like the user to fill the tags in a single textbox. So I created a TagString...

How scope of variable defined/flows in SQL statements compared to LINQ

Here in this video at 11th minute, while explaining about strange structure (compared to SQL) of LINQ query, Anders Hejlsberg says that "Scope of variables in SQL flows backward in SQL", What does he mean by that? I'm totally confused... :( ...

LINQ to SQL array always returns first item?

i am using LINQ to SQL. My Database has 3 columns Ref, Due_amount, Due_Date. Data may look like this, for example. 10 02/08/2009 00:00:00 175.0000 10 02/09/2009 00:00:00 175.0000 10 02/10/2009 00:00:00 175.0000 10 02/11/2009 00:00:00 175.0000 10 02/12/2009 00:00:00 175.0000 10 02/01/2010 00:00:00 175.0000 ...

Binding multiple fields to listbox in ASP.NET

I'm fairly new to asp.net and especially LINQ and SQL. Say I have a table "Employees" with fields "Lastname", "Firstname", and "ID". I want to bind this to a list box. I want the list box to display it's contents like "$LASTNAME, $FIRSTNAME" and I want the value of each item to be "ID". It's trivial to bind either name column to the l...