linq

Using LINQ to count value frequency

I have a table ID|VALUE VALUE an integer field with possible values 0 - 4. How can I query the count of each value? Ideally the result should be an array with 6 elements, one for the count of each value and the last one is the total number of rows. ...

How to put two condition in lambda expression

I have two Repeater Control var list = from i in DA.obm_view_studentLists where i.FranchiseID == FranchiseID && i.ExamDate == DateTime.Parse(this.pallavi.DropDownSelectedValue) select i; I want to get result in 1 go from database. this._approvedStudentList.DataSource = list.Select(e => e.ApprovedByOBM == true); this._pendingStudentL...

Using ref parameters in linq

I have a function that takes a ref parameter and would like to use it in a linq query but the compiler complains. The function is called BreakLine and breaks a string up into lines based on a line length, the ref parameter is used to keep track of where it is in the string on each call: string BreakLine(string text, int lineLimit, ref ...

Exposing SQL fired when LINQ executes

Morning all. Just a quick one for you - where can I find the SQL that is executed when a LINQ statement fires? I have the following code that works a treat, var r = (from p in getproductweightsbuyer.tblWeights where p.MemberId == memberid && p.LocationId == locationid ...

ASP GridView DataBind with Entity Navigated property

Hi, I have a GridView DataBind with entity ClassA's properties that is working fine. I am able to directly bind below properties in ASPX file. ClassA.Id ClassA.Name etc. But ClassA also have a navigation property to related ClassB. I would like in a the same GridView to display related classB's properties. I try to bind the following ...

Aggregate functions in LINQ

Hello all I have the following LINQ conditional where clause query that produces a result of weights: From this, I'd like to take the result set and join on another table, tblPurchases var result = weights.Join(getsuppliersproducts.tblPurchases, w => new { w.MemberId, w.MemberName, w.LocationId, w.UnitId }, p => new { p.M...

LINQ execute SQL query with output parameter

Hi! I need to execute SQL query with output parameter. For example, SELECT @Count = COUNT(*) FROM dbo.SomeTable SELECT * FROM SomeTable WHERE Id BETWEEN 1 AND 10 After quering I need to know the @Count value. How can I do it with LINQ without using a stored procedure? Thank you. ...

How do I buid a WCF Query on the fly?

I'd like to build some linq or alternatively, build a query string on the fly and pass it to a WCF Data Service (with Entity Framework data model). Something like this: public List<DocumentInformationRecord> SearchClientDocs(string clientCode, string clientName, string contactName, string groupCode, string groupName, ...

linq return only one row

I am using linq over dataset have multiple columns and grouping on one column with this code: Dim Groups = From n In data _ Group n By s = n.Field(Of String)("name") Into Group Select s but it results in only the first row and I checked the data it's supposed to return 13 rows. ...

asp.net 3.5 linq batch update?

Hi Looking for a bit of advice on this. I have a fairly robust .net web app where up till now ive only had to deal with records (in a sql server database) one at a time. I now have a requirement to do a batch update, of probably around 100 - 200 records at a time. I prefer using LINQ for querying, I know its not the best but just throug...

Difference between System.Linq.Dynamic and System.Linq?

Using ReSharper, I occasionally get quick-fix suggestions for importing a namespace for a LINQ operation. So given the following code in a brand-new class: linqToSqlDataContext.Customers.Count(); I get a quick-fix drop down as follows: Which should I choose, and what is the difference between them? ...

C# how do I implement inheritance using linq?

Hi, I have two lists based on the same class. I would like one list to inherit the values of the other list's class properties. class feature { Guid id; string featureName; string featureType; ..... } List <feature> companyFeatures; List <feature> divisionFeatures; The list of features is set at the company level. When a...

Linq to Sql object not populated

I am new to Linq and am struggling with what I think is a deferred execution problem. I have a data layer in my application which uses Linq to Sql and then passes the entity through to the viewmodel using a WCF service (MVVM architecture). The object gets serialised at this point. I am passing thorough an Employee object which shoul...

minimum value in dictionary using linq

Hi I have a dictionary of type Dictionary<DateTime,double> dictionary How can I retrive a minimum value and key coresponding to this value from this dictionary using linq ? ...

C#: Iterating through a data table: Rows, Select() or AsEnumerable()

foreach (DataRow row in myDataTable.Select()) foreach (DataRow row in myDataTable.AsEnumerable()) foreach (DataRow row in myDataTable.Rows) Any differences? ...

Linq Puzzle: How do I convert this foreach to linq syntax?

List<string> nameSpaceSuffixes = GetSuffixes(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach(var suffix in nameSpaceSuffixes) { if (assembly.GetName().Name.EndsWith(suffix)) Register(container, assembly, suffix); } } ...

What are some Linq Gotchas that you've come across?

In the spirit of this question, I'd like to know what Gotchas you've come across in Linq. The reason I'm posting this is because I came across a brain teaser today, and I want to share it with the rest of you. note: I've posted it as an answer ...

Expression<Func<T,bool>> - How to Handle Ambiguous Method Signatures?

Hi Guys, I have an interface contract that looks like this: ICollection<FooBar> FindByPredicate(Expression<Func<FooBar,bool>> predicate); ICollection<Foo> FindByPredicate(Expression<Func<Foo,bool>> predicate); ICollection<Bar> FindByPredicate(Expression<Func<Bar,bool>> predicate); Foo and Bar are concrete classes which inherit from t...

SQL Server version of Oracle's CONNECT BY in LINQ to show hierachy

I have successfully simulated an Oracle CONNECT BY statement in SQL Server 2008 by following these 2 previous answers here and here and adjusting to get the results I need. But how do I do this in LINQ? Here is an example of what I am doing using a dummy database: CREATE TABLE Employee( EmployeeID INT IDENTITY(1,1) PRIMARY KEY, Depar...

How can i convert my Sql codes to Linq?

i try to convert my SQL code to linq but i cannot: Alter PROCEDURE sp_MatchCTallyToTask AS BEGIN select * from Task where MPDReference in( select MPDReference from Task intersect select ENG_CUSTOMERTALLY_CUSTOMERTASKNUMBER from dbo.ENG_CUSTOMERTALLY) END GO public List<Task> TaskList() { return engCtx.Tasks...