linq

Nested LiNQ to XML

I am looking for a nice way to save / load the following. I want to save as XML and ideally looking to use LiNQ (namely to help me learn LINQ) I don't know how to do nested linq writes though. Can anyone help? /// <summary> /// /// </summary> public class ErrorType { List<ErrorType> _childErrors; public String Name { get...

Serialization in WCF/LINQ to SQL

I created my dbml file with the tables that i need. One of the method generated is as such, names have been changed and it is not syntactically correct. But my code compiles with the original method created. [Association(Name="Clients_ToEmployee", Storage="_ToEmployees", ThisKey="ClientID", OtherKey="ClientID")] [DataMember(Order=70, Em...

How to search List<> with Json Generic deserialized object

I need to filter a generic List with data from a Json object. I have the deserialized object in a list with {name:'', value:''}. I need to search a data contract (which is also a list) with name as the field to search, and value as the value of the field. How do I accomplish these as they are generic. Here is the method: public List...

What is the best practise design for a scalable web application involving session state

The reason I ask this is recentlydesigned an application , initially wanted to use no session state to keep things simple, but eventually succumbed to the ease of the session state idea for storing state. I was aware that moving to a web farm solution would involve configuring session state to run in sql. However I had never run across a...

Custom Linq Ordering

I decided to rephrase my question. I have over a thousand folders, each folder contains one or more files with the following names: Unordered: Alison.ext Heather.ext Molly.ext Paula.ext Sam.ext Ordered: Molly.ext Sam.ext Heather.ext Alison.ext Paula.ext I would like to write an expression to sort this list as described above. Sorry ...

How can this be achieved in LINQ ?

I want to rewrite this, maybe using predicates, or Lambda, how can I do this? serviceResponse = client.Authorize(....); string authorizeResponse = string.Empty; foreach (CdcEntry element in serviceResponse.Cdc) { authorizeResponse += element.Name + Environment.NewLine; foreach (...

problem with LINQ, I dont know what is it !

I moved my project from my computer to athor computer and when I opened it, I facing this problem with LINQ: http://www.rofof.com/img2/6bvnql3.gif pleas how can I solve it ? ...

[Solved] Specified cast is not valid. ListView and Linq

Hello guys. I have problem when i using ListView and Linq as datasource. The error down: Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: S...

LINQ to SQL - How to deal with changes to database

I'm fairly new to LINQ to SQL, so I could be missing something basic here. I created a LINQ to SQL layer, generated all the dbml files etc., and created a LINQ query which worked fine. I then made a change to the database, and wanted to get that change reflected in the ORM layer. To do this, I deleted my ORM layer and created a new on...

LINQ Expression Help - Querying my Object Model

I am new to LINQ and am trying to query my Business Layer (BLL), i.e. Model. I have looked at some samples, but none seem to assist me in my scenario. Let's say I start w/ creating a method, I would think: public void GetLinqQuery() { EmployeeCollection employeeList = EmployeeController.GetAll(); // my usual way of getting employee l...

C# LINQ: Sequence Contains No Elements Error (but I want to check for null!)

Hello, I have the following problem: public Boolean Exists(String userName) { IRepository<User> = new UserRepository(); User user = userRepository.First(u => u.Name == userName); if (user == null) return false; // Exists! return true; } The problem is now, that I can't check the User object for null. Before I...

lambda extension to combine lists

how do i use the second expression to select only those with ID from the first? var list1= from x in objects select x.id; results=results.Where(r=>r.id== ???? ) I want the results to be only those with id from listA tia EDIT:i stand corrected, there was another issue causing problem which i will ask about separately. ...

LINQ to pull back object graph

Is it possible to group by more than one group in LINQ? For instance, I have this query (obviously incomplete) from lxr in LOCATION_XREFs join l in LOCATIONs on lxr.LOCATION_SKEY equals l.LOCATION_SKEY join c in COMPANies on l.COMPANY_SKEY equals c.COMPANY_SKEY join prlx in PeopleRoleLocationXrefs on lxr.LOCATION_XREF_SKEY ...

LINQ to Dataset WHERE clause NULL reference exception

First, take a look at this thread http://stackoverflow.com/questions/881225/linq-to-dataset-dbnull-problem-null-reference-exception The link above provides you how to LEFT JOIN and then SELECT column that have NULL value in it without taking Exception error My problem is I want to COUNT the column is null in WHERE clause (after my LEF...

Linq and comparing two date columns

I get a notsupportedexception when i run the following linq query. Any ideas how to resove it var declines = from d in _Db.DeclinedSettlementSet where d.STATUS == Status.REPORTED && d.ADD_DATE < d.EDIT_DATE.AddDays(-3) ...

ADO.Net Entity Framework/Linq

I'm look at learning a bit more ASP.Net MVC and Linq To Entity. I'm working on a project using this and am having a problem with the following line of code ViewData["ProjectName"] = db.Projects.FirstOrDefault(p => p.ProjectId == task.ProjectId).ProjectName; It works fine when the record exists but if no record exist it errors becau...

ADO.Net Entity Framework Relationships

I have 2 tables that are mapped in my entity model which are basically this Tasks ( TaskId TaskName Description ProjectId (Foreign Key) ) Projects ( ProjectId ProjectName ) I retrieve my task using Linq to Entities like this Tasks task = (from t in db.Tasks where t.TaskId == id select t).FirstOrDefault(); The tas...

Problem with Unit test and SQL database Connection

I am having a problem with a unit test I have created. First time doing this so I am not sure why I am getting this error <DeploymentItem("ETDS.exe")> <DataSource("System.Data.SqlClient", "Data Source=Foo;Initial Catalog=FooDB;Integrated Security=True", "User_Names", DataAccessMethod.Sequential)> <TestMethod()> _ Public Sub ValidateUser...

Opinions on Expression Tree Serialization Library from CodePlex?

did someone tried this code library and have opinion about it? http://code.msdn.microsoft.com/exprserialization 10x ...

Conditional LINQ where statement?

I have a linq statement that I want to add an additional where clause to if a drop down index is not 0. people.Where(n.surname == "surname" || n.forename == "forename" && (dropdown.SelectedIndex > 0) ? n.id = dropdown.SelectedValue : n.id > 0).Select(n => n); I am not even sure if what I am trying is possible?? I would like to do th...