linq

Which kinds of queries is better for querying against conceptual model in Entity Framework?

There are 3 way for querying against conceptual model in EF : LINQ to Entity Entity SQL Query Builder Methods Which one is better for which situation? Is there any performance issues for these 3 type of querying? ...

Adding Property to custom LINQ to SQL class not reflected in client side

Hi, The application I am working uses a Silverlight on the client side and gets data from a database using the LINQ to SQL object explosed through a contract as in WCF. I am trying to add a property to the object of a LINQ query result as follows: public partial class Linq_data_class { public String NewProperty { get; set; } } T...

Order by descending based on condition

Hello All, I want to write a LINQ to Entity query which does order by ascending or descending based on input parameter, Is there any way for that. Following is the my code. Please suggest. public List<Hosters_HostingProviderDetail> GetPendingApproval(SortOrder sortOrder) { List<Hosters_HostingProviderDetail> returnList ...

How to create an extern alias for System.Core?

I absolutely need an extern alias for System.Core in my project. Unfortunately, in a .Net 4.0 project, you cannot even add a reference to System.Core because, apparently, the build system includes it by default. Does anyone have any idea on how I can coerce the system to let me specify an extern alias for this lib? Thanks! ...

Where Not In OR Except simulation of SQL in LINQ to Objects

Suppose I have two lists that holds the list of source file names and destination file names respectively. The Sourcefilenamelist has files as 1.txt, 2.txt,3.txt, 4.txt while the Destinaitonlist has 1.txt,2.txt. I ned to write a linq query to find out which files are in SourceList that are absent in DestinationFile list. e.g. here ...

Order by descending is not working on LINQ to Entity

Order by descending is not working on LINQ to Entity In the following Query In place of ascending If I keep descending it is not working. Please help me out var hosters = from e in context.Hosters_HostingProviderDetail where e.ActiveStatusID == pendingStateId orderby e.HostingProviderName ascending select e; return host...

Resources for a quick introduction to Linq & ADO.NET Entity Framework

Hi all, I've just started working with LINQ (mainly in context of the ADO.NET Entity Framework) and currently learning the basics from The ADO.NET Entity Framework Overview @ MSDN and this LINQ tutorial. Any other online primers recommended for beginners to learn LINQ fundamentals? I generally do know the syntax and how to get the obje...

Simple LinQ question: convert [][] to []

Hello, I would like to get collection or list of Item objects, but I get array of arrays now. Item[][] s = employees.Select(e => e.Orders.Select(o => new Item(e.ID, o.ID)).ToArray()).ToArray(); Can anyone select me solution to do it? P.S. just LinQ solution :) ...

L2E many to many query

I have four tables: Users PrivilegeGroups rdPrivileges LinkPrivilege ----------- ---------------- --------------- --------------- userId(pk) privilegeGroupId(pk) privilegeId(pk) privilegeId(pk, fk) privilegeGroupId(fk) name code priv...

What is my problem with ASP.NET pubslishing?

I am done testing my site and I want to upload it to a site like this http://www.university.edu/mydepartment/myname the admin told me the server runs on .NET 3.5. So i used Linq ... now i tried to upload the site by two ways: when i just copy everything (with modification of web.config database settings) i get an error: CS0246: T...

Help writing a linq query in subsonic

I'm busy writing some extension methods and so far have been going fine. I have a method getCities that takes in an IQueryable qry and is supposed to return all of the regions in qry that have a region type of city. I tried using linq to do it, but gave up and am currently using a for loop. It works, but its bugging me. I have comment...

Help me with Linq query please

I'm trying to get all the assets where Class property equals to one of the values in selectedIClassesList; Something like this: from x in Assets where selectedIClassesList.Contains(x.Class) select x ...

Help me construct this Linq statement

There should be a simple Linq query for what I'm trying to accomplish, but I'm producing some ugly code. I have two tables, one of issues and another of issue status. There is a one-to-many relationship between issue and issue status. When an issue is created an IssueStatus is also created with the status field set to "Open" when it is ...

How to replace for-loops with a functional statement in C#?

A colleague once said that God is killing a kitten every time I write a for-loop. When asked how to avoid for-loops, his answer was to use a functional language. However, if you are stuck with a non-functional language, say C#, what techniques are there to avoid for-loops or to get rid of them by refactoring? With lambda expressions and...

Fill WinForms DataGridView From Anonymous Linq Query

// From my form BindingSource bs = new BindingSource(); private void fillStudentGrid() { bs.DataSource = Admin.GetStudents(); dgViewStudents.DataSource = bs; } // From the Admin class public static List<Student> GetStudents() { DojoDBDataContext conn = new DojoDBDataContext(); var query = (from s in conn....

LINQtoSQL Custom Constructor off Partial Class?

Hi all, I read this question here: http://stackoverflow.com/questions/82409/is-there-a-way-to-override-the-empty-constructor-in-a-class-generated-by-linqtosq Typically my constructor would look like: public User(String username, String password, String email, DateTime birthday, Char gender) { this.Id = Guid.NewGuid(); ...

L2E delete exception

I have following code to delete an user from database: try { var user = from u in db.Users where u.Username == username select u; if (user.Count() > 0) { db.DeleteObject(user.First()); db.SaveChanges(...

L2E these two are the same thing?

Are the following two statements the same? Users user = db.Users.First(u => (u.Username == username)); and var user = from u in db.Users where u.Username == username select u; Users aUser = user.First(); ...

When is LINQ (to objects) Overused?

My career started as a hard-core functional-paradigm developer (LISP), and now I'm a hard-core .net/C# developer. Of course I'm enamored with LINQ. However, I also believe in (1) using the right tool for the job and (2) preserving the KISS principle: of the 60+ engineers I work with, perhaps only 20% have hours of LINQ / functional par...

Using DataGridViewRowCollection object in LINQ

I'd like to use a DataGridViewRowCollection in a LINQ expression using extension methods and lambda expressions. Unfortunately, the extension methods are for types IEnumerable, which DataGridViewRowCollection doesn't implement. The funny thing is, I can use LINQ here with the SQL-like syntax: IEnumerable lRows = (from DataGridViewRow ro...