linq

create a generic method that sorts List<T> collections

What I used to do is create a case switch that sorts my LINQ in this format: List<products> productList = GetAllLists(); switch (sortBy) { case "name": return productsList.OrderBy(pl => pl.Name); case "date": return productsList.OrderBy(pl => pl.DateCreate); } which, in the long run, becomes cumbersome. I wanted to hav...

Like in Lambda Expression and LINQ

Simple Question how to have something like this customers.where(c=>c.Name **like** "john"); i know this isn not possible but i was wondering how can i have something similar. thanks in advance. ...

Find an attribute that contains a ceratin string and modifying its Value in c# using LINQ

Hello, I'm trying to find the first attribute in an xml file that contains the string "name" (case insensitve) in it and then change its value. Here is an example of my xmls //XML 1 <CtApproachTypes DataclassId="1992A9CE-B048-4676-BFD4-FD81F1A65401" EntityId="1992A9CE-B048-4676-BFD4-FD81F1A65401" Name="PAR" Remark="No Rema...

Linq SubmitChanges() function - when to call?

When manipulating data using Linq, how often does the SubmitChanges() method have to be called? In my project, there are a few tables related with foreign keys. In the creation SQL, these foreign keys are constrained so a record that is part of a relationship can't be deleted without the dependant records being deleted first. Therefore...

Apply operations on a one-dimensional array of instances in one line, using LINQ

Consider the following structures: internal struct Coordinate { public Double Top { get; set; } public Double Left { get; set; } } internal struct Dimension { public Double Height { get; set; } public Double Width { get; set; } } internal struct Property { public Boolean Visible { get; set; } internal String La...

Linq to NHibernate issue

I currently have code which produces the following LINQ expression (taken from the WhoCanHelpMe showcase project). Its purpose is to bind together two expressions but I don't know if the following is actually a valid expression: .Where(p => (p.PostCodes .Any(pc =>(pc = value(PatchByPostCodeSpecification).postCode)) && In...

How to execute code as a part of the LINQ query

I have a query that looks like this: var results = from person where <here I need to do something like if person is of type Employee, call person.GetSalary() > 100000 but if the person is of type Contractor, I need to execute several lines of code before doing a person.GetSalary() > 100000 sele...

Intersection of 6 List<int> objects

Hi, As I mentioned in the title I've got 6 List objects in my hand. I want to find the intersection of them except the ones who has no item. intersectionResultSet = list1. Intersect(list2). Intersect(list3). Intersect(list4). Intersect(list5). Intersect(list6).ToList(); When one of them has no item, normally I...

How to Bind Exclude more than one property from a model with linq to sql asp.net mvc

I have a form with a select box on it. The linq entity has a selectList as a public property on it. I'm currently excluding it from the entity like this [Bind(Exclude = "taskDeadlineTime")] I now want to add a second drop down, and I'm getting this error when I try to UpdateModel() No parameterless constructor defined for this obje...

How to select/remove elements from a Dictionary<string, List<string>> based on some criteria

I am trying to remove elements from a Dictionary<string, List<string>> in C# when the count of the list<string> is lesser than or equal to 1. I got some code working but it is not elegant and I have a gut feeling that this can be done elegantly in linq. This is the code I have now Dictionary<string,List<string>> FindAnagrams(...

LINQ + WCF + Transactions

I have a relatively simple use case which is failing. Consider the following code: [OperationBehavior(TransactionScopeRequired = true)] public IEnumerable<StatusRecord> ReadActive(int contactID, bool isActive) { var result = from n in ORM.Default.Table<StatusRecord>() where n.lng_contact_id == contactID && n.dte_effec...

How to make this LINQ To entity method work when it has Nullable LEFT JOIN

Here is the code snippet, actually the whole method. This method works f,ine when NULLAblE Foreign Key Refernces has value. When the value is not there, then this method does not work. My idea is to get all the records even if the references column is NULL. Here is the code : public List<PostedJob> GetPostedJobs(int startingIndex, int ...

LINQ WITH VS 2008

Is the VS 2008 professeional Edition fully support with linq to sql Thank ...

Traverse a Linq Expression to set the value of a property field

This is a very complicated question even though it looks simple. I think I would have to traverse the entire expression tree unless someone knows a better way. Let's say I have a user object class User { public UserAccount Account {get;set;} } class UserAccount { public Name {get;set;} } var user = new User() { Account = new Us...

Casting a list of lists to IGrouping?

I have some code that creates a list of lists. The list is of this type: List<List<Device>> GroupedDeviceList = new List<List<Device>>(); But need to return the result in the following type: IEnumerable<IGrouping<object, Device>> Is this possible via a cast etc or should I be using a different definition for my list of lists? ...

Select files from IEnumerable<>

Hi there, I have the following: var selectedFilesToReplace = new List<string>(); foreach (string file in files) { selectedFilesToReplace.AddRange(listUploadedFiles .Where(x => Path.GetFileNameWithoutExtension(x) == file)); } that fill the selectedFilesToReplace collection with a set of FULL path files. I need to select o...

autogenerated sql code: single backslash as an escape character is failing.

Hello everyone, I'm querying an oracle 9i database with: SELECT * FROM table WHERE column LIKE '%' || ‘someText’ || '%' ESCAPE '\'; and it fails with the error "escape character must be character string of length 1" ( ORA-01425 error), while succeeding in an oracle express 10g database. Making it a double backslash (ESCAPE '\\') solv...

LINQ Join With Multiple Where Clause

Hello all. I am struggling once again so any help would be gratefully received. I have the following LINQ that pulls back a list of data: public static List<tblWeight> GetWeights(string memberid, string locationid, string buyer, string subcategory, string product) { MyEntity getweights = new MyEntity (); ...

C#/.NET/WPF: Obtaining subsets from LINQ, rather than the IEnumerable

I have some trivial code that looks like this: SortedDictionary<String, long> d = new SortedDictionary<String, long>(); // d is then populated with an expensive time-consuming process ListBox lb = new ListBox(); lb.ItemsSource = d; // THIS WORKS GREAT Now what I'd like to do is dynamically show a ...

c# linq to sql with a stored procedure containing dynamic sql

Hi, I have a stored procedure that contains dynamic sql to return a result set. The query runs fine, but I can't use it via Linq to sql. It appears that the Data Class designer deems that the query only contains one column (Location) rather than the correct number. I'm guessing its because the dynamic sql means that the columns are no...