linq

Expression.Constant(value, type) type is unknown. How to define the type

Hi there: So the problem is I have the following line wehre value is a string var filterValue = Expression.Constant(value, property.Type); if property.Type is a string everything is fine however the type really could be anything, like a decimal? I dont know how to make this work for all different types I have this function priva...

LINQ API Clarifications

I know Microsoft Implementation of LINQ.Are Different LINQ APIs availabe (third party)? ...

Linq used to find index of value

Can linq somehow be used to find the index of a value in an array? For instance, this loop locates the key index within an array. for (int i = 0; i < words.Length; i++) { if (words[i].IsKey) { keyIndex = i; } } ...

LINQ To Rest missing functions like Count() and First(). How do I add those to my ADO.NET Data Service?

I have an ADO.NET data service based off of a LINQ-To-SQL class. I can query this ADO.NET service using LINQ to Rest queries which build simple rest statements. But if I want to use other functions that work in LINQ-To-SQL I get an error that the LINQ-To-Rest statement can't be made into a rest query. Example: X.Data.Cust.CustData db =...

Convert Expression<Func<TInterface, bool>> to Expression<Func<TImplementation, bool>>

Another Linq question =) So I have a certain interface that I can code against and an expression that has this signature Expression<Func<TInterface, bool>> At some point I will need to use that expression but it needs to look like this Expression<Func<TImplementaion, bool>> I ve tried this Expression<Func<TImplementation, bool>...

Linq select different columns

I'd like select different column based on some variable instead of doing something like this if(selectLastName) var res = from e in ctx.Employees select new {e.FirstName, e.LastName}; else var res = from e in ctx.Employees select new {e.FirstName} How can I re-write this ? ...

Can LINQ use binary search when the collection is ordered?

Can I somehow "instruct" LINQ to use binary search when the collection that I'm trying to search is ordered. I'm using an ObservableCollection<T>, populated with ordered data, and I'm trying to use Enumerable.First(<Predicate>). In my predicate, I'm filtering by the value of the field my collection's sorted by. ...

Custom LINQ provider for Excel spreadsheets?

Does anyone know a good custom LINQ provider to query data from Excel spreadsheets? ...

WPF: ObjectDataProvider (with LINQ to XML) or XmlDataProvider---which do you prefer?

I've just read “How to perform WPF Data Binding using LINQ to XML” and this leads me to the question, ObjectDataProvider (with LINQ to XML) or XmlDataProvider---which do you prefer? Should I just fall in love with the XAML-based LINQ to XML approach or are there performance issues here? This is a snippet from the aforementioned article:...

Linq to ADO.NET parent/child query help

Hello I want to use Linq to ADO.NET to fetch all rows that match the criteria below from a DataTable. Select all rows where "parentId" equals "id" of a row where "parentId" equals null. Order by "Name". Can someone tell me how to accomplish this (preferably using both Query Syntax and Method Syntax), and possibly point me to where I...

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

I am getting the above error when I upload my app to the hosting company.(asp.net) DB is a local sql mdf in app_data directory. on local asp.net dev server everything is ok. I am using LINQ to SQL Classes, is there anything that can be related to that? Thanks in advance ...

Is an outer join possible with Linq to Entity Framework

There are many examples of outer join using Linq to Sql, all of them hinging on DefaultIfEmpty() which is not supported with Linq to Entity Framework. Does this mean that outer join is not possible with Linq to Entity using .NET 3.5 (I understand that DefaultIfEmpty is coming with 4.0 --- but that's not an option at this time for me) C...

LINQ to IEnumerable<MyObj>

Hi, I have a class MyObj and a collection IEnumerable. Some of the columns are wholly empty (i.e. == NULL) across all rows and therefore I want to create an IEnumerable<> of the members of MyObj which hold a non-null value. If I could predict the members of MyObj which would be of interest I'd do something like: var part = from e...

Set values with a Linq-Query ?

In my application I have a list of items I need to sort by price and set a rank/position index for each item. I need to store the rank because the price may change afterward. At the moment I am doing it like this: var sortedlistKFZ = from res in listKFZ orderby res.Price select res; if (sortedlistKFZ.Any()) { int rankPosition = 1; ...

Wanted : List of data following certain rules concerning dates

Hi all, here is my problem. I have a list of data, sorted by dateStart : index dateStart dateEnd value [0] 2009-11-01 04:20 2009-11-01 05:40 5 [1] 2009-11-01 06:30 2009-11-01 08:42 10 [2] 2009-11-01 07:43 2009-11-01 16:12 0 [3] 2009-11-01 10:43 2009-11-01 14:34 -12 [4] 2...

Do the Nerd Dinner models use best practices for disposing objects?

I've been looking at the Nerd Dinner code and one thing they do in their models, is create an instance of the DataContext like this: public class DinnerRepository { private NerdDinnerDataContext db = new NerdDinnerDataContext(); public IQueryable<Dinner> FindUpcomingDinners() { return from dinner in db.Dinners ...

LINQ to XML: How to clone nodes while retaining annotations?

Try this: var doc1 = XDocument.Load(@"C:\any.xml", LoadOptions.SetLineInfo); var doc2 = new XDocument(doc1); doc2 no longer has any line number information. Digging in with Reflector, I can see that when the nodes are cloned from doc1 to doc2 this does not preserve the annotations on the XObject base type, which includes the line numb...

Strongly Typing a LINQ Query using multiple keys of complex objects

I can't figure out how to define the object used in my LINQ grouping query to allow them to be strongly type. I've build a grouping query that uses two complex objects as keys. The query works, but I would like to be able to declare the return object type. I have a complex type... Public Class Student Public Name As IndividualsNa...

How do you use Models in a master page with ASP.NET MVC?

public ActionResult Index(){ var dataContext = new DataEvidencijaDataContext(); MembershipUser myObject = Membership.GetUser(); string KorisnickoIme = myObject.UserName.ToString(); var user = from i in dataContext.korisniks where i.korisnik1 == KorisnickoIme ...

Returning Entities + Extra Data with ADO.NET Data Services

Trying to figure out the best way to accomplish this. So I have a table of Stores with properties: StoreID, Name, Latitude, Longitude, etc. I'm using ADO.NET Data Services (Astoria) to create a web service that will show nearby stores given a radius and a coordinate. I made a Service Operation to take the params and return the result...