linq

Convert DataTable to LINQ: Unable to query multiple fields

Importing a spreadsheet I have filled a DataTable object with that data and returns expected results. Attempting to put this into a format I can easily query to search for problem records I have done the following public void Something(DataTable dt) { var data = from row in dt.AsEnumerable() select row["Order"].ToS...

Selecting distinct objects from collection of objects using lambda expressions

We have a project using Fluent NHibernate. There is an object called BluePart with a property of Oem of type Oem. public class BluePart : DomainEntity { ... public virtual Oem Oem { get; set; } } The Oem object has several properties including OemCode and OemDescription. public class Oem : DomainEntity { ... public vi...

Need help with Linq filtering in C#

What I have is a collection named HourList which is made up of Hour objects. Two of the properties on an Hour are EmployeeId and Hours. Employees punch in and out and an hour record is created. So at the end of a week I am delivered an HourList of mulipple Hour objects for mulitple employees from our DAO. It is requested that a report be...

What kind of, does there exist a, data framework like this?

What I want to do is: Load values for a program from a file. Read/Add/Change those values. Save those values back to the file I would like to be able to have a database be the file I want as much of the data as possible to stay in memory, so I'm not hammering the file I would like to query using Linq or be able to use a Standard Query ...

LINQ Equivalent of SQL

I have to translate the following SQL Query into LINQ equivalent SELECT 0 AS DOCID, 'All_Forms ' as PAGE, 0 AS PAGENUMBER UNION SELECT DOCID, (CAST(IsNull(CUSTOMPAGE,PAGENUMBER) AS VARCHAR(10)) +'. '+TITLE ) AS PAGE, PAGENUMBER FROM Medical_Reports WHERE PAPERSTYLE='Normal' AND PAGENUMBER<>10000 ...

Taking object without empty properties in Linq

I want to take pa but empty MG props. Parent pa = new Parent() { MC = new Child[] { new Child() {M1 = 1}, new Child() {M1 = 2}, new Child() {M1 = 3}, },...

Guidance on designing a solution - XML files vs database

I am thinking of storing bunch of data in XML files. Each file will has information about a distinct element lets say contacts. Now I am trying to do retrieve a contact based on some information eg: Find all the contacts who live in CA. How do I search for this information? Can I use something like LINQ. I am seeing XElement but does it ...

Invoke an Expression in a Select statement - LINQ to Entity Framework

I'm trying to use an already existing Expression building class that I made when trying to do a select clause, but I'm not sure how to attach the expression to the expression tree for the Select, I tried doing the following: var catalogs = matchingCatalogs.Select(c => new { c.CatalogID, ...

Linq custom comparer for contains?

I have 2 lists. I want to compare every element with every element for both lists using LINQ (versus using say a nested loop). But, the Contains does not meet my needs because I need to do a custom comparison. I would imagine a custom comparer is what I need but not 100% sure. I do not think this should be too difficult but not sure exa...

Dealing with VB.NET Linq formatting in Visual Studio?

Does anyone else wrestle with getting VB.NET Linq code formatted the way they want it in Visual Studio? What are some tricks you have for how do you deal with it? I know that Visual Studio lets you uncheck the option for "Pretty listing (reformatting) of code", but most of the time it's a really handy setting to keep on. And with a te...

How to remove items from multidimensional List using LINQ

Public Class GroupSelect Public Property RowNo() As Integer Get Return m_RowNo End Get Set(ByVal value As Integer) m_RowNo = value End Set End Property Private m_RowNo As Integer Public Property GroupNo() As Integer Get Return m_GroupNo End Get Set(ByVal value As Integer) m_...

use linq with webservice

Hi there, I am creating a HttpHandler to output some xml. I have been given a webservice that I need to use and modify the output slightly. My question is how do I work with the service... I reference the webservice then what do I do? do I need to create a datatable and then use linq to output the xdocument or is there an easier way? ...

ASP.NET MVC: DropDownListFor doesn't select any option

I have this to populate a drop down list in an ASP.NET MVC view. <%= Html.DropDownListFor(model => model.Bikes, Model.Bikes.Select( x => new SelectListItem { Text = x.Name, Value = Url.Action("Details", "Bike", new { bikeId = x.ID }), Selected = x.ID == Model.ID, })) %>...

Use Linq and lambda to flatten a list

Hi there I have a class. public class MedicalRequest { private int id private IList<MedicalDays> Days private string MedicalUser ... } and another public class MedicalDays { private int id; private DateTime? day private MedicalRequest request ... } I have the MedicalUser so I'm able to select an I...

LINQ to entities - left join with condition

I have a table GameVersion with FK (allowing nulls) to Game table. When I do this: GameVersion[] q = (from gv in db.GameVersion.Include("Game") select gv).ToArray(); It works OK, while iterating GameVersion objects I can see null references to Game in some records (just like on the databse), so it works like...

Lambda Expression Weirdness in Linq to SQL Where condition

Hi, I am working on an ASP.Net MVC application which uses the repository pattern with linq to sql as my data source. In my repository I expose the following method: public IEnumerable<T> Find(Expression<Func<T, bool>> where) { return _context.GetTable<T>().Where(where); } I am able to call this by saying: repository<User>.Find(u...

Insert Queries Can Only Cause Concurrency Issues With Select Queries?

This is just for my own understanding of how concurrency issues work. Let's say I have an insert statement that runs at the same time as a select query. If the insert statement occurs while the select query is still running, will the select query show a conflict because the number of rows to select has changed? Or is it that concurrenc...

Great project ideas for MVC/LINQ/jQUERY

I'm looking for a couple projects to help me learn MVC, LINQ, and maybe a little jQUERY. I've got a couple ideas - the top one is creating a complete bug tracking system or support ticket system. Do any of you have any suggestions regarding what I could try? I would rather have something more advanced and something with actual utility. ...

c# bindingsource and linq

Hi all, I have a bindingsource which has been filled out by tableadapter.fill(DS, param1); lets say that this bindingsource has : char num A 1 B 2 C 3 how do I get num value with given char 'A' using linq? I could literate using foreach (DataRowView data in this.p_EM_Select_Event_TypeBindingSource) but I would li...

Is it possible to Merge stacks with LINQ

I'm just starting to learn LINQ, I'm wondering if it would be possible to group the elements in 3 different stacks using LINQ. this is what I have, could it be possible to add more than one array in the from clause, and how? var uniqueValues = from n in valuesStack.ToArray() group n by n into nGroup ...