linq

Using linqpad as primary query tool

A member of my team recently moved to LinqPad as his primary query tool (still will use SQL Studio at times) for the simple purpose of forcing himself to make using LINQ more natural to use. I thought this was a pretty good idea and am considering asking the rest of my team to make this switch. Does anyone have any thoughts / ideas on ...

Discriminator Property

Hello all, Working through this step by step guide. I am trying to create the inheritance between BirthAppointment / tblAppointment. However I need the Discriminator Property to be set to appCatId. The appCatId is held within tblAppointmentType. How can I access this. Thanks in advance for your help. Clare ...

LINQ: find all checked checkboxes in a GridView

Consider the current algorithm below that iterates through a GridView's rows to find whether the contained Checkbox is selected/checked. List<int> checkedIDs = new List<int>(); foreach (GridViewRow msgRow in messagesGrid.Rows) { CheckBox chk = (CheckBox)msgRow.FindControl("chkUpdateStatus"); if (chk.Checked){ //we want the GridV...

Why does trying to access an attribute in LINQ-to-XML give me an error?

According to my LINQ book, this slightly altered example should work. Why does it tell me "Object reference not set to an instance of an object"? using System; using System.Xml.Linq; namespace TestNoAttribute { class Program { static void Main(string[] args) { XDocument xdoc = new XDocument( ...

Linq not properly generating view by not allowing nulls

I have a view: SELECT dbo.Theme.ThemeID, dbo.ThemeObject.XLocation, dbo.ThemeObject.YLocation, dbo.ThemeObject.ThemeElementTypeID AS ThemeObject_ThemeElementTypeID, dbo.ThemeImage.ThemeImageData FROM dbo.Theme INNER JOIN dbo.ThemeObject ON dbo.Theme.ThemeID = dbo.ThemeObject.ThemeID LEFT ...

Could Not Load File or Assembly Sharepoint 2007 WebPart

Hey SO: I am playing around with Sharepoint 2007. I have a virtual machine (win server 2k3) with an instance of sharepoint server 2007 running on it. I am now working on creating web parts. I have successfully created simple ones, such as this one that displays text: public class SimpleWebPart : WebPart { private string _displayTex...

asp.net MVC Storefront showing too many queries?

I am studying Asp.NET MVC Storefront application and there is some help needed with LINQ. For example study this Partial Code. Here is GetCategories Function which retrieves All Categories and their corresponding Products. In a View I only needed Category Names but when called this Function and checking in SQL profiler it shows too many ...

LINQ - writing a query with distinct and orderby

Hi, I'm quite new to LINQ. Suppose that I had the following table: Incident ID DeviceID Time Info 1 1 5/2/2009 d 2 2 5/3/2009 c 3 2 5/4/2009 b 4 1 5/5/2009 a In LINQ, how could I write a query that finds the most recent and distinct (on Device ID) set of incidents? The result I'd like i...

Using a single Func<T,bool> with Where() and inheritance

I'm trying to use a single Func<T,bool> definition to handle a class and its inheritor. This is what I have: Func<Job, bool> ValidJob = j => !j.Deleted && !j.OnHold && j.PostDate <= DateTime.Now && j.ExpireDate > DateTime.Now; public class JobExtended : Job { } So, given that, the following works: IQueryable<Job> jobs = ......

What is the difference between using Join in Linq and "Olde Style" pre ANSI join syntax?

This question follows on from a question I asked yesterday about why using the join query on my Entities produced horrendously complicated SQL. It seemed that performing a query like this: var query = from ev in genesisContext.Events join pe in genesisContext.People_Event_Link on ev equals...

Linq to Sql Force Order By

Is there a way in Linq to Sql (.net 3.5) to specify that when you get the children of a particular record, to force the list of children to come back in a specific order? For example, I have a list that has a "DisplayOrder" on it. When I ask my parent record/object for it's property that returns to me this list, I want Linq to Sql to r...

Choosing Database and ORM for a .NET project

I'm working on a .NET application using Silverlight on the client side. Now I've come to the point where I want to throw out my static dummy data on the server side and add a database instead. For the database I'd love to use one of them ORM's where I can simply tag my model classes and the database tables are built for me. I did some ...

What is the best way to cast each item in a LINQ to Entities query to in interface?

I have an entity object 'User' which implements 'IUser': IQueryable<User> users = Db.User; return users; But what I actually want to return is: IQueryable<IUser> So what is the best way to convert IQueryable<User> to IQueryable<IUser> without actually running the query? Right now I am doing this but it seems like a hack: IQ...

Linq2Sql -> Searching the database against a local collection of values - "Queries with local collections are not supported"

I am running up against the wall with Linq2SQL. I love it, its amazing the flexibility, but I have run up against interesting hangups. I hope its just my lack of knowledge of it, and there really is a solution. Take for example... a linq2sql query like this: // some local collection of ids var terminalID = new List<int>(){1, 2, 3, 4, ...

Mimicking SQL Insert Trigger with LINQ-to-SQL

Using LINQ-to-SQL, I would like to automatically create child records when inserting the parent entity. Basically, mimicking how an SQL Insert trigger would work, but in-code so that some additional processing can be done. The parent has an association to the child, but it seems that I cannot simply add new child records during the Dat...

Validate DateTime's are sequential by month

I have a list containing 60 DateTime objects (sorted in ascending order) and need to validate that each date is 1 month greater than the previous one in the list. For example, the following list of dates would be valid because they increment by one month with none missing: Jan-2009 Feb-2009 Mar-2009 Apr-2009 However, the followi...

How to Group more than one table By in LINQ

So, I understand that group by works basically like this: var query = from c in context.Contacts join o in context.Orders on c.Id on o.CustomerId group c by o.Id select new { g.Key, g.Sum(c => c.Whatever) }; Grouping like that only allows me access to the contents of c. But what if I wanted data fro...

How can I use this T-SQL query in LINQ / Entity Framework?

I'm only dealing with one database table / entity object: NodePath. Given a particular Node, I want to get only a subset of all its NodePaths according to this query: select * from NodePath where NodeId = @GivenNodeId and Id in ( --active paths select a.Id from NodePa...

Test for List<T> membership using a List<T>

Does anyone know if there is a way to test for list membership utilizing a list. For example I have a class named Membership which has a property Rebates which is of type List<Enums.RebateType>. I want to test using a lambda expression to see if that list contains any rebates that are of a specific type. My orginal lambda expression is a...

Linq | Date | Subtraction with matching issue

I want to check 1 day old created record(s), and below is my code. my problem is, it does returning any record even if I do have a match. And even I run it on LinqPad, It just outputing blank result. from x in Users where (DateTime.Today - x.CreatedDate).ToString().Equals("1.00:00:00") select x but when i try to remove the "where" f...