linq

In what scenarios would i want to create custom business objects from Linq to Sql results?

A simple linq to SQL query Might return a product object. Obiously I could pass this object to my business layer, then read and update the data, directly against that object. I've seen a bunch of implementations where following the execution of the linq query the resulting object is mapped (via automapper or manually) to a custom busin...

Dictionary<Foo, List<Bar>> How to assign the list to a property of the key with LINQ?

I have a dictionary as described in the question. My Foo class looks like this: class Foo { List<Bar> Bars {get;set;} } I want to run through the dictionary, and assign the KeyValuePair value to the Key's Bars property. Is that possible? I have something like this but it's a little wonky: List<Foo> foos = new List<Foo>(); foreach(...

Cant Update row with Decimal DataType in Entity Frameworking using mySql

I have been working on this problem for too long. All of my select and insert commands work fine but when it comes to updating decimal columns i get errors. I am using the following software ASP.Net v4 MySQL Connector Net 6.3.3 MySql Server 5.0.51a Product Class public class Product() { public int ProductID {get;set;} publi...

LINQ group items. A single item may be in several groups

I have an IEnumerable of items that I would like to group by associated categories. The items are grouped by the categories that are associated with them - which is a List - so a single item can potentially be a part of multiple categories. var categories = numbers.SelectMany(x => x.Categories).Distinct(); var query = from cat i...

Linq Subquery Where Clause

I need some help with thsi linq query. It shoudl be fairly simple, but it is kicking my butt. I need to use a subquery to filter out data from the main query, but every path I have tried to use results in failure. The subquery by itself looks like this. int pk = (from c in context.PtApprovedCertifications where c.FkosParticip...

How do get a strongly typed single value using LINQ

I am using LINQ to interact with data in a DataSet in a C#.NET program. The data is imported into the data set from an XML file so that is where it gets it's schema. I want to be able to grab a single row from the table and then access the specific columns of that row in a strongly-typed manner (with intelli-sense). I think I am close on...

Find parent based on children properties linq to sql

Lets say we have a sql relationship that can be modeled like this using C# classes public class Parent { public int ID { get; set; } public List<Child> Children { get; set; } } public class Child { public int ID { get; set; } public Parent Parent { get; set; } public int Number { get; set; } } I also know that th...

In Memory Data Cache for Performance in .Net Applications

Hey All - We have an application (rules engine) that has a lot of tables in memory to perform certain business rules. This engine is also used for writing back to the database when needed. The DB structure is denormalized, and we have 5 transactional tables, that also sometimes need to be queried for reporting. The issue here is, we w...

C# Linq eqiuvalent of SQL Count()

I have a fairly complicated join query that I use with my database. Upon running it I end up with results that contain an baseID and a bunch of other fields. I then want to take this baseID and determine how many times it occurs in a table like this: TableToBeCounted (Many to Many) { baseID, childID } How do I perform a li...

Entity Framework, extending adding "filters"

Hello I have lots of extended "filters" such as this one: public static IQueryable<Customer> ByCustomerID(this IQueryable<Customer> qry, int customerID) { return from c in qry where c.CustomerID == customerID select c; } To GetCustomers() (IQueryable), such as .ByCompanyID() etc etc, and I would like to...

Creating an object with dynamic properties in C#

Hi, I'm using linq to load a csv file, but because the csv may have any number of columns, the object that it returns will need dynamic properties, and I can't figure out how to do that. var data = from row in csvData let col = row.Split(',') select new { Field1 = data[0], ...

LINQ query and IDisposable

I'm currently writing a piece of code that does some searches which returns IDisposable objects (DirectoryEntry to be specific from an ADAM instance) and I end up with code similar to using(var entry = (from result in results let entry = result.GetDirectoryEntry() where entry != null ...

Help needed on SQL query to Linq Conversion

Please help me write LINQ for this SQL select svc.SvcName, svcOptions.SvcOptionName, svcMap.Price from svcMap inner join svc on svcMap.SvcId = svc.SvcId inner join svcOptions on svcOptions.SvcOptionId = CASE WHEN (svcMap.DesiredSvcOptionId <> 0 AND svcMap.DesiredSvcOptionId <> svc.DisabledSvcOptionId) THEN ...

WCF Service along With LINQ to SQL in asp.net

Hi, I have Created the WCF Service in my application which involves LINQ Concepts but i cant understand how to call that service to my web pages.Can anyone say me how to call the service that i have created to my application with the detailed steps along with some sample codings So that i can proceed further? Thanks In Advance. ...

LINQ question ... need to get element with min value

Im new to linq so i still struggle .... I have a collection of controls (each has a Location of type Point). I need to remove the control with the lowest Y value (top control) from the collection. An example would be most appreciated ! ...

late binding in linq

I have a simple LINQ query that is going against a collection. Dim oList = From w In Os Order By w.ClassTitle Descending Select w What I'd like to be able to do though is pass into this whether it's descending or ascending. I'm not sure how to do that. Also, if I were to have a where clause in here.. sa...

Counting in a Linq Query

I have a fairly complicated join query that I use with my database. Upon running it I end up with results that contain an baseID and a bunch of other fields. I then want to take this baseID and determine how many times it occurs in a table like this: TableToBeCounted (One to Many) { baseID, childID } How do I perform a linq ...

what is the maximum objects supported by LINQ

I am trying to use LINQ for certain operations. So there may be chance that millions of record will be used in LINQ. So is it worth to use LINQ in this case? what is the maximum object limit to use LINQ? I am reading records from database and check some conditions and store in List<Result>. Result is a class. Then performing LINQ query...

Transaction for sequential numbering in LINQ to SQL.

I have a scenario where just before I insert a JobCard record, I need to generate an ID number (not the identity column PK), that is an increment of the last ID number in the DB. How do I wrap this in a transaction in LINQ to SQL so that no other JobCard record can be inserted between the time I select the last ID number and insert my J...

linq infinite list from given finite list

Given a finite list of elements, how can I create a (lazily-evaluated, thanks LINQ!) infinite list that just keeps iterating over my initial list? If the initial list is {1, 2, 3}, I want the new list to return {1, 2, 3, 1, 2, 3, 1, ...} ...