linq

LINQ: orderby with dynamic string parameter

HI, i want to do this: orderby = "Nome, Cognome desc"; var timb = time.Timbratures.Include("Anagrafica_Dipendente").Where(p => p.CodDipendente == 1); if(orderBy != "") timb = timb.OrderBy(orderBy); Is there any method for pass a string parameter to Orderby thanks ...

data model problem

public ActionResult Index() { testEntities6 devicesEntities = new testEntities6(); List<DevicesModel> devicesModel = new List<DevicesModel>(); var device_query = from d in devicesEntities.device join dt in devicesEntities.devicetype on d.DeviceTypeId equals dt.Id join l in devicesEnti...

like operator in linq

i need to use the like operator in a linq query for this: timb = time.Timbratures.Include("Anagrafica_Dipendente") .Where(p => p.Anagrafica_Dipendente.Cognome + " " + p.Anagrafica_Dipendente.Nome like "%ci%"); How can i do? ...

Linq - Grouping where items fall in multiple groups?

Is it possible using Linq to create a group where items fall into more than one group? Using the following trivial example: public class Data { public string ID; public int From; public int To; } And this list: List<Data> data = new List<Data>() { new Data() { ID = "A", From = 1, ...

System.MissingMemberException was unhandled by user code

I'm using this code: Dim VehiclesTable1 = dsVehicleList.Tables(0) Dim VT1 = (From d In VehiclesTable1.AsEnumerable _ Select VehicleTypeName = d.Item("VehicleTypeName") _ , VTypeID = d.Item("VTypeID") _ , ImageURL = d.Item("ImageURL") _ , DailyRate = d.Item("DailyRate") _ ...

Teaching coworkers LINQ...

I have set myself upon a journey to educate my coworkers (all have accepted my mission, even the boss). Every day I seem to find a piece of code that could have been less error prone if my coworkers knew more about the framework, better-know-framework (in courtesy of DNR ;)) is part two of my teaching process. First part is teaching my c...

*Right* outer join in LINQ

Is it safe to say that there is no such thing as a right outer join in LINQ? I know to effectively create one, you'd just swap the tables in a left outer join. But can you apply the DefaultIfEmpty() method to the table on the left side of the equijoin to make it a right outer join? ...

Is it wise for me to use this LINQ statement for grabbing a subset of items based on a dynamic subset?

I am working on an ASPX page that needs to handle multiple different kinds of data. I came up with a potentially ideal fashion to fetch the information I need, but am unsure if it is as good an idea as it feels. Basically, I need to filter a set into a subset, but which values I filter by will differ by circumstance. I constructed the fo...

Association in Linq To SQL showing as an EntitySet<>, why?

I am having a lot of trouble coming up with the Linq equivalent of this legacy stored procedure. The biggest hurdle is it doesn't seem to want to let me add a second 'clause' on the join with tblAddress. I am getting a Cannot resolve method... error. that tblBusiness.tblAddress is seen as an EntitySet<tblAddress> See bottom for curre...

C# XElement: Node Formatting with HTML

I'm extracting XML node from an XElement. When I use XElement.Value it strips any HTML that may be in the node. I know that if I do XElement.ToString() I can keep the HTML, but it also gives me the node tags. Is there any way to extract the content of a Node as is without the HTML being stripped out? Cheers. ...

LINQ query with specified number of rows in a subquery problem

I'm trying to write the following query in LINQ, but can't seem to get it correct. select p.* from Person p inner join PersoniPhones i ON p.PersonID = i.PersonID where p.PersonID in ( SELECT PersonID FROM ( SELECT Top 10 PersonID, iPhoneID FROM iPhone ORDER BY LastPlayedDate DESC ) as t ) ...

How can I use LINQ to find the Intersect between two properties of the same collection?

Given an IList<Foo> with a data set that looks like this: ID CHILD PARENT TYPE 1 102 101 UPSELL 1 103 101 UPSELL 2 102 101 BONUS 2 104 103 BONUS 3 102 101 BONUS 4 102 101 PRODUCT 4 104 102 PRODUCT How can I use LINQ to find a child which has a parent with the s...

How can I get a List<int> from LINQ to XML that produces List<List<int>> ?

I have an XML snippet as follows: <PerformancePanel> <LegalText> <Line id="300" /> <Line id="304" /> <Line id="278" /> </LegalText> </PerformancePanel> I'm using the following code to get an object: var performancePanels = new { Panels = (from panel in doc.Elements("PerformancePanel") ...

How to join results from two different sets in LINQ?

Hi, I get some data about customers in my database with this method: public List<KlientViewModel> GetListOfKlientViewModel() { List<KlientViewModel> list = _klientRepository.List().Select(k => new KlientViewModel { Id = k.Id, Imie = k.Imie, Nazwisko = k.Nazwisk...

LINQ-to-XML to DataGridView: Cannot edit fields -- How to fix?

I am currently doing LINQ-to-XML and populating a DataGridView with my query just fine. The trouble I am running into is that once loaded into the DataGridView, the values appear to be Un-editable (ReadOnly). Here's my code: var barcodes = (from src in xmldoc.Descendants("Container") where src.Descendants().Count() > 0 ...

LINQ to XML - How to get Dictionary from Anonymous Object?

Currently I'm getting a list of HeaderColumns from the following XML snippet: <PerformancePanel> <HeaderColumns> <column performanceId="12" text="Over last month %" /> <column performanceId="13" text="Over last 3 months %" /> <column performanceId="16" text="1 Year %" /> <column performanceId="18" text="3 Years % p.a."...

How to get List of results from list of ID values with LINQ to SQL?

I have a list of ID values: List<int> MyIDs { get; set; } I'd like to pass this list to an interface to my repository and have it return a List that match the ID values I pass in. List<MyType> myTypes = new List<MyType>(); IMyRepository myRepos = new SqlMyRepository(); myTypes = myRepos.GetMyTypes(this.MyIDs); Currently, GetMyTyp...

Linq: Search a string for all occurrences of multiple spaces

I have a string and i want to find the position of all the occurrences of multiple spaces. Im writing a punctuation checker. I would like to parralelise this operation using parallel linq but in the meantime im just looking for the linq method to get me started. ...

How to order a List by the order of another List?

I have a method as follows. It returns a list of MyTypes which appear to be ordered by myType.Id ascending by default. I'd like this list to be ordered by the ids parameter I pass into the method. public List<MyType> GetMyTypes(List<int> ids) { return (from myType in db.MyTypes where ids.Contains(myType.Id) select new My...

How to use linq to find the minimum

I have a class A { public float Score; ... } and an IEnumerable<A> items and would like to find the A which has minimal score. Using items.Min(x => x.Score) gives the minimal score and not the instance with minimal score. How can I get the instance by iterating only once through my data? Edit: So long there are three main solutions: ...