linq

Linq to SQL File Size

Hi, What I wanna learn is if we put every table into one LinqToSQL file, do we lose performance ? Is it better to put each table in different LinqToSQL Files or it's the same thing with putting in single one. I hope I could explain my question. Thanks and Regards... ...

List Manipulation in C# using Linq

using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace ConsoleApplication1 { public class Class1 { static void Main(string[] args) { List<Car> mylist = new List<Car>(); Car car1; Car car2; Car car3...

Delphi Prism and LINQ to SQL / Entity Framework

I have found many posts and examples of using LINQ-syntax in Delphi Prism (Oxygene), but I have never found anything on LINQ to SQL or Entity Framework. Is it possible to use LINQ to SQL or Entity Framework together with Prism? Where can I found such an example? Update: Olaf is giving an answer through his blog The question is now if...

How To Update Data With Linq By Attach Method

I have a update method in my data layer such this: public clacc datalayerSec_User private objUIData as new UIData Public Function Update(ByVal objUser As SEC_USER) As Boolean Try objUIData.SEC_USERs.Attach(objUser) objUIData.Refresh(RefreshMode.KeepCurrentValues, objUser) objUIData.SubmitChanges(ConflictMode.ContinueOnConf...

C# List<> GroupBy 2 Values

I'm using C# on Framework 3.5. I'm looking to quickly group a Generic List<> by two properties. For the sake of this example lets say I have a List of an Order type with properties of CustomerId, ProductId, and ProductCount. How would I get the sum of ProductCounts grouped by CustomerId and ProductId using a lambda expression? ...

Linq 2 SQL or Linq Entities

I am starting to design a new application and what I am wondering is peoples opinions on Linq2SQL or Linq2Entities and what they feel is the better technology for rapid development. I am also doing some research into ADO.net data services. ...

Extract column of doubles from a DataTable

Is there an easier way to achieve the following? var obj = from row in table.AsEnumerable() select row["DOUBLEVALUE"]; double[] a = Array.ConvertAll<object, double>(obj.ToArray(), o => (double)o); I'm extracting a column from a DataTable and storing the column in an array of doubles. Assume that table is a DataTable contai...

How To Project a Line Number Into Linq Query Results

How can I project the row number onto the linq query result set. Instead of say: field1, field2, field3 field1, field2, field3 I would like: 1, field1, field2, field3 2, field1, field2, field3 Here is my attempt at this: public List<ScoreWithRank> GetHighScoresWithRank(string gameId, int count) { Guid guid = new Guid(gameId);...

Calling fellow code nerds - Alternatives to Nested Loops?

It is not uncommon for me (or likely anyone else) to have a list of objects I need to iterate through and then interact with a list of properties. I use a nested loop, like this: IList<T> listOfObjects; IList<TProperty> listOfProperties; foreach (T dataObject in listOfObjects) { foreach (TProperty property in listOfProperties) ...

Is linq a cursor?

I'm familiar with .NET and with SQL. Now I'm looking at the new LINQ and it looks to me just like a cursor. I understand the ease of use, etc., but if I do a LINQ-to-SQL query with a foreach loop, am I just using a DB cursor? Or is there some sort of magic behind the scenes where LINQ collects all the data at once and feeds it to my p...

Adapting Linq Entity objects to Domain objects

Hi, I have the following code which adapts linq entities to my Domain objects: return from g in DBContext.Gigs select new DO.Gig { ID = g.ID, Name = g.Name, Description = g.Description, StartDate = g.Date, En...

Stored Proc not executing with LINQ

This issue is driving me mad. I have several tables defined, and CRUD stored procs for those tables. I have wired up the stored procs to the tables in Visual Studio using the dbml mapper. All work fine, except for one table. The insert stored proc is not being hit for my history table. The insert property in the table in the dbml map...

Does LINQ Support Composable "OR Queries"?

In another posting: Does Linq-To-Sql support composable queries there was discussion on how to compose/concat where clauses dynamically. This appears to be done with an "AND" (i.e. the first where clause and the second where clause are joined by an AND). What I am wondering is if there is a way to compose Linq queries with an OR. Exam...

How to create a reference to an existing record

Hello, go easy on me, it's my first question :) I've been working with linqToSql for about a month, and there is just this one thing that is bothering me... Lets say I have an Entity Object called "Customer" and another called "CustomerType", Customer as a reference to CustomerType. When inserting the Customer I need to set the Custum...

How to do this in ADO.NET Entities Framework

I have a table called BlogPost which has a 1-to-many relationship with the Comment table. (In Comment, there's a foreign key BlogPostId.) Now I want to retrieve all posts as well as the latest comments of each post. I've tried with s/t like below but it doesn't work. from r in Db.BlogPost select new {Post = r, LatestComment = r.C...

How to implement a custom rating system (with a declining date relevance)

I'm working on a site similar to digg in the respect that users can submit "stories". I keep track of how many "votes" and "similar adds" each item got. Similar adds are defined as two users adding the same "link". Here is part of the algorithm (essentially the most important): y = day number sy = number of adds on day y ∑ y[1:10]...

Access LINQ-2-SQL DataContext in entity class

Is there any simple way to access the DataContext in a linq2sql entity class. I'm trying to create something like EntitySet but I cannot figure out how the EntitySet has access to the context that created the entity object in the first place. I want to have a regular linq2sql entity class with a way for the class to access the DataCont...

Force Full Path in the Connection String of Linq DataContext

I'm using System.Data.Linq.DataContext file for accessing a mdf Database I want to use the Database from the project directory and not the one created by the debugger in the Debug directory. The problem is when I edit the Connection String and choose the path for AttachDBFilename, VS2008 automaticly substitutes my project directory wit...

LINQ Error Invalid Column Name on Group by sum.

For some reason, when using two sums on a group by, i run into the error "invalid column name 'id'. When i only do one sum, it works as expected. The following fails and throws the error: from pd in PrDetails.Where(_pd => _pd.PrId == 46) group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs } into g sele...

LINQ GroupJoin innerKeySelector/outerKeySeletor issue with two DataTables

Hi All, Given a DataSet, I'm left joining DataTables[1-n] onto DataTable[0]. I have created a method with a signature as follows: public DataTable LeftJoin(DataSet ds, params JoinKey[] JoinKey) Notes: The return type is a DataTable, which is the resulting left join. DataSet ds is a collection of DataTables for joining. JoinKey is ...