linq-to-entities

Constraining queries based on aggregations of properties of associations

Quick question: would this trigger one query per each Tag item? public static IQueryable<Tag> WhereTagHasLivePosts(this IQueryable<Tag> q) { return q.Where(t => t.Posts.Where(p => DateTime.Now >= p.PublishTime && p.IsPublished == true).Count() > 0); } t.Posts.Where is actually an extension on IEnumerable, rather than IQueryable, s...

Dynamic query with Linq To Entities

I've got an EDM with two tables Product and ProductCategory with a many-to-many relationship between both. What I'm currently trying to do is to build a dynamic query to select the products related to the categories the user has selected through the UI. In short I should build a query like the following but based one or more categories...

How to delete data with linq to entities

This code is giving me this error: The object cannot be deleted because it was not found in the ObjectStateManager using (var context = new MvcApplication4.Entity.test2Entities()) { var q = (from t in context.tag where t.tag_id == tag select new ...

Bind gridview inside of usercontrol from content page

hi is it possible to bind gridview inside of usercontrol from content page, if so how? ...

LINQ join with a literal values

This is kind of hypothetical as I'm thinking about how to design this. Consider this query with some literal integer values in the join criteria: Select * From LeftPeople l Inner Join RightPeople r On r.RecordId = l.RecordId and r.ResultId = 3 and l.ResultId = 7 Would this be the correct equivilant in LINQ? It seems kind of a cludg...

Dynamic creation of models - entities using Asp.Net MVC

So, i have my database sorted like: Products_001 Products_002 Products_003 Let's say, if a customer logs in and his id is 001, he is only entitled to use the database-table products_001. Can i dynamically create his model - entity using Asp.Net MVC, and how would i do this? ...

LINQ - How to Construct Query When the Column Name is not known until Runtime?

Given: string metadata.XAxisColumn -- contains a column name (e.g., "Date") string metadata.YAxisColumn -- contains another columnname (e.g., "Close") When I know the names of the columns up front, of course I can do: var query = from record in myView where record.Date >= startDate && record.Date <= endDate select record.Clo...

Does applying additional clauses to a compiled query cause a recompile?

If I have a compiled entities query via CompiledQuery.Compile and I then tack on another .Where() clause or .OrderBy() clause, do these addition clauses force a full recompile, a partial recompile, or no recompile? ...

Chain together multiple complex WHERE clauses in LINQ to SQL

This is the pseudo-SQL I want to generate: SELECT * FROM Table WHERE Column1 = @Value1 OR Column2 = @Value2 The problem is, sometimes the second one should not be included. I was hoping to chain together .Where() clauses like so: var query = context.TableName; query = query.Where(t => t.Column1 == value1); if (NeedsToBeIncluded(valu...

Traversing ASP.NET HTML Elements using LINQ

Guys, Assuming I have the following ASP.NET HTML Code: <html> <head><title>Test Page</title></head> <body id="bodyID"> <asp:Label runat="server" id="lbl1" text="First Name:" /> <asp:TextBox runat="server" id="txt1" /><br /> <asp:Label runat="server" id="lbl2" text="Last Name:" /> <asp:TextBox runa...

LINQ to Entities Question - All objects where all items in subcollection appear in another collection?

Hey all, Hopefully I can explain this to where it make sense, but I'm trying to get a list of objects out of a master list using a speicific and complex (complex to me, at least) set of criteria. I have a Class called TableInfo that exposes a List of ForeignKeyInfo. ForeignKeyInfo has a string property (among others) called, Table. I...

Is there a per-property deferred loading option in Linq-to-Entities as there was in Linq-to-Sql

First I want to pre-thank anyone who helps with this. Back when I was programming in Linq-to-Sql there was a per-property option for deferred loading which was perfect for excluding large binary fields in a table without actually having to write special select statements to exclude each one. I can re-architect the database to make the b...

Project a DateTime from an IQueryable to a string in a custom class

Hi. I have this code running on the server part of my Silverlight application with WCF Ria Services: public IQueryable<PersonePM> GetPersoneByCognome(string cognome) { return (from p in ObjectContext.Persone where p.Cognome.ToLower().Contains(cognome.Trim().ToLower()) select new PersoneP...

Passing a Linq expression as a string?

The following code works fine using (var ctx = new MyEntities()) { var devices = ctx.Devices .Where(x=> x.Device == "TEST") .ToList(); return devices; } What I would like to do is to pass in the expression that goes in the “Where” clause. I see that it can t...

Is there any alternative to DateTime.Ticks or DateTime.TimeOfDay in Linq-To-Entities?

Hi there! I'm writing a log parser for an asp.net mvc2 web application. I use Entity framework as a model and logging is done both using my manual engine together with SqlServer2008 CDC feature. When inserting, or editing a row in a database, the action is being logged. However, there's a small lag between occuring changes in actual ta...

Cannot cast anonymous return type from query to an entity type

I'm struggling with a (usually simple to deal with) problem. I have a database containing a "measurements" table. Each measurement has a timestamp (datetime), a value (decimal), a measurement type (foreign key to a lookup table) and belongs to a "capacity item" (a master table). I imported the SQL database in Entity Framework and creat...

does IQueryable<T> only get returned from the Linq to Sql or Linq to Entities classes?

In the book I'm reading "Pro Linq in C# 2010" (APress, Freeman and Ratz) the author states that IQueryable will only be returned from the classes in the Linq to Sql namespace, not in the general Linq namespace. I was surprised by this, since I thought anything that had a Where on the end had to be IQueryable. Turns out I was wrong, Where...

How would you implement a form submission templating system

hello, I need to implement a form tamplate system. The form needs to be very dynamic. It will need: Multiple textboxes Multiple dropdown menus Multiple Number fields Multiple Date fields Single Image field Single Submit button Any or all of these fields can be blank but must follow the field type. Therefore letters cannot go in numbe...

Adding data to database using MVC - with FK relationships.

Hi- I have a database and I am using the Entity Framework with Linq 2 Enities. I am working with ASP.NET MVC 2. I have a database with two tables as shown bellow: Classifieds Catergories ID(PK) CatID(PK) CatID(FK) CatName Desc ... Obviously when the user adds a new classified and when they c...

How to create a dynamic linq to entities query

Hello all. Now this is probably really easy but being the tool that I am, I'm not sure the best way to attack this problem. I have a DAL and a load of methods using EF that populate drop down lists in a UI. i.e. material, source. From these, I want the user to populate a gridview with the product data based upon their criteria they s...