linq

query a sub-collection of a collection with linq

I've got a collection of products, and each product object has it's own ProductImages collection. Each ProductImage object has a IsMainImage bool field. I'm having a hard time building a Linq query like this: select products.productimages.imagename where products.productid == 1 and product.productimages.ismainimage == true Can ...

want a Query to make order by variable in Linq query

How to make order by Column variable because I have a dropdown on page and I want to show grid according to sord order selected in this Dropdown e.g Price, Code, rating, description etc etc. and I donot want to write a separate query for each column. from lm in lDc.tbl_Products where lm.TypeRef == pTypeId orderby lm.Code ascending se...

How to convet mutliple SQL left joins to Linq-To-SQL

I have a user table, a user_items table, a user_to_group table and a group table. How would I convert the following SQL query to the correct Linq-to-sql query? select user.username, user.email, user_items.item_number, item_types.desc, [group].name from user left join user_items on user.user_id = user_items.user_id left join item_types ...

LINQ insert related records

Hi I have a database with a "configs" table each new row in the configs table is 4 a different client which can config his environment to his liking (theme,companyname,language, culture...) one record,lets say id=-1, is the default config. all new configs should copy everything from there i want that each time i (the main admin) add a ne...

Call method on LINQ query results succinctly

Hi, I'd like to call MyMethod on each object from a LINQ Query, what is the best way to do this? Currently I am using: .Select(x => { x.MyMethod (); return x; }).ToArray(); ToArray() is needed for immediate execution. Is there a simpler way to write this (without a foreach) Thanks ...

Use Linq to filter Hashtable based on a property of Values custom object

I have a synchronized Hashtable with int as the key, and a custom class called "Job" as the value. I would like to filter this Hashtable based on a property in my Job class called "JobSize". JobSize is just an enum with values Small, Medium, and Large. It's fine if it needs to be converted to another collection type to do this. I kno...

How can i fill 1D array from 2D array and how can i sort 1D array?

hanks everybody to help my idiot problem (look my before post:) ) . But i exactly need below. I should fill 1 dimentional array from legth of per cell Datatable. and sort 1D array linq and also without linq int[][] lengths; using (DataTable table = GetTable()) { lengths = (from DataRow row in ta...

Is there a coherent way to use ICriteria and Linq to NHibernate in the same query?

It looks like this question: NHibernate.Linq and MultiCriteria provides a potential way to combine using Linq to NHibernate and ICriteria together in the same query (in my case, to add fulltext search predicates to Linq to NH queries). If you wrapped the Linq to NHibernate IQueryable<T> with your own implementation, you could even inc...

IQueryable .Except() is not resulting what I expect!

I have the following object: Line{ String Content; Type type;} And I have, IQeryable<Line> lines, which I perform operations against. I selected certain lines where line.Content.Contains('x') = list1, and now am trying to get to the rest of the lines i.e. lines - list1 and for this am using list2 = lines.Except(list1); but that...

IEqualityComparer for class with many properties

Hi all, which is the best implementation for IEqualityComparer for this class ?? The entity has 7 properties. Thanks in advanced. [Serializable()] public class ServidorSeleccionadoDto { [XmlAttribute()] public int Id { get; set; } [XmlAttribute()] public string Nombre { get; set; } [X...

DAAB 5.0 with LINQ-to-SQL mimicry

Hello, I was looking at the EntLib 5.0 video on their website and I saw a preview that uses like a different IDataReader to fill-in objects to work like a LINQ-to-Objects shortcut (instead of a LINQ-to-SQL). I think it uses sprocs class, but I couldn't find it on the library. Any idea where I can read more about it? Google isn't cooper...

Autocomplete extender 'extended' across entire data table.

Hello all I have a request to create an auto complete that will search an data table. Is this achieveable quickly and simply or is it a case of writing a reasonable amount of code? Originally, I have been using a webservice and linq to point at a single column's worth of data (IDDesc) and pull back the list of products: Product.FinalP...

How can i select data with linq part by part of rows?

i want to select data from datatable or sql table or list 50 rows by 50 rows. Forexample: var list = from x in dtable select x ----- > first 50 rows Click next button for GridView next 50 rows . And than 50 rows whli clicking next button to monitor GridView? For Example Data : static DataTable GetTable() { ...

How to implement an IN clause in LinQ

Hi there, I have two ILIst of these objects: class ProductionMachineType { string code { get; set; } IEnumerable<string> ProductionToolsLink { get; set; } } class ProductionTools { string code { get; set; } } I am looking for a fast Linq method that make me able to query the IList<Produ...

Unable to cast object of type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' to same type

I am getting this error when I publish my code to the server (GoDaddy), but locally when I run in code Unable to cast object of type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' to type 'System.Data.EnumerableRowCollection`1[System.Data.DataRow]' The code that the error is triggering on is: foreach (DataRow dr in ds....

custom string sorter

I want to sort a collection by one of the properties which is a string, but i dont want to sort alphabetically. Here is my code IEnumerable<Item> items = Repository.Query<Item>().OrderBy(r=> r.Status) Status is a string but i want to sort in a particular order (not alphabetically) how do i inject a custom sorter in the above syntax...

LINQ multiple order by

Hi, I have created a function that has the follwing parameter: List<Expression<Func<CatalogProduct, bool>>> orderBy = null This parameter is optional, If it is filled it should create a order by and than by constuction for me, so that I can order the result on the SQL server. I tried: IOrderedQueryable temp = null; ...

Read XML file using LinQ

Hi, I have one xml file. That xml file have multiple elements. I want to read these elements and bind into datagrid using Linq in C#. ...

LINQ Average TimeSpan?

Hello all, I have a database table that contains entries for start time and end time of an event. I would like to take those entries and find the average length of an event. The subtraction is no problem. However, when I try to get the average value, the compiler complains. Here is my current LINQ query: public TimeSpan? getAverageTim...

Read XML file using LinQ

Hi, This is my XML File. <?xml version="1.0" encoding="utf-8"?> <locstrings> <section name="section1"> <locstring ID="sectionID1"> <Name>SectionName1</Name> </locstring> </section> <section name="section2"> <locstring ID="sectionID2"> <Name>SectionName2</Name> </locstring> <locstring ID="Sec...