linq-to-entities

Entity Framework - associated entities question

I've noticed that if i have an Pk/FK association, the FK ID is removed from the entity in the designer. How do I join query statements? Basically I'm looking for some good Linq to Entity video tutorials (sorry, I'm an audio/visual learner) ...

Using LINQ how do I have a grouping by a "calculated field"

I am using LINQ to EF and have the following LINQ query: var results = (from x in ctx.Items group x by x.Year into decades orderby decades.Count() descending select new { Decade = decades.Key, DecadeCount = decades.Count() }); So this kind of gets me to where I want to be, in that I get the...

Entity Framework - how do I use the entity associations?

When I have tables in my database that have PK/FK relationships (int) and when they are modeled by the Entity Framework designer everything seems as it should be. I can write the code below and everything seems like it's going to work fine as well but then when I run the code I get an error on the project.Status.StatusName saying the Ob...

Entity Framework - how do I use the entity relationships in my extended classes?

I am trying to extend the partial classes that the entity framework creates so that I can more easily work with objects like in the code below (please let me know if there's a better or more exceptable way of doing this with the entity framework) Public Sub New(ByVal ProjectID As Integer) Dim proj As Project = (From p In db....

LINQ - Update null integer data field

I have got a field with data type int? price and allow null, when I set book.price = null; and update, it is not saved and does not throw any exceptions, when I change value # null, it is ok. I want set it null, plz help. ...

Adding to the Where clause of an Update in LinQ-to-Entities

Let's say I have a table called Product, with three columns: Id, CustomerId, Name. Id is the primary key. The schema is outside of the control of my group, and we now have a requirement to always provide CustomerId as a parameter for all queries (selects, updates, deletes). It's a long story I'd rather not get into ... it involves trig...

How to create a dynamic Linq Join extension method

There was a library of dynamic Linq extensions methods released as a sample with VS2008. I'd like to extend it with a Join method. The code below fails with a parameter miss match exception at run time. Can anyone find the problem? public static IQueryable Join(this IQueryable outer, IEnumerable inner, string outerSelector, string in...

Would you use LINQ to SQL for new projects?

I've been investigating what data layer to use for a new web-based project I'm designing and I'm very keen to look at incorporating LINQ to SQL. Its apparent simplicity, flexibility and designer support really appeals and the implicit tie-in to SQL Server is fine. However, it has been announced recently that LINQ to SQL will be taking a...

ADO.NET Entity Framework and Linq to Entities

I'm confused about Linq to Entities. Is it the new name of Entity Framework or are they different things? ...

"NOT IN" clause in LINQ to Entities

Hi, Is there anyway I can create a not in clause like I would have in SQL Server in Linq to Entities? Cheers Paul ...

Adding and Updating with LINQ to Entities

We are using L2E and REST in our project, and while I have been able to retrieve data from the db without issue, I am still not able to update or add new records to the db. I imagine that it's a syntax problem (we're still new to to linq), but I haven't been able to figure it out. We initially load the data in the dataservicecontext, a...

Which is the best book out there to learn Linq, including Linq to Entities?

I heard lots of reviews on the book Linq in Action, but it does not cover Linq to Entities. Please provide your feedback on the books you may have read. ...

Do I have to make a select query to create a relationship in Entity Framework?

I want to create a Blog object which has a relation between User. To create the relationship do I have to select User entity first, then set it to User property of Blog object? In Entity Framework samples suggest to set the User object to ViewState and retrieve it when you need to create the relationship, like a basic cache. Is this ne...

Error: The object cannot be deleted because it was not found in the ObjectStateManager.

Trying to get a handle on Entity Framework here and I am hitting some speedbumps... I have a Get() method that works fine and has been tested, buut my Delete method is not working: public static void Delete(string name) { J1Entities db = new J1Entities(); db.DeleteObject(Get(name)); db.SaveChanges(); }...

Is there a way to export the .edmx diagram from VS2008 to Visio?

Some people want to see the DB structure and dont have VS, is there a way to do this? Or any other way to export it outside of a screencapture (it is a huge diagram). Thank you. ...

Doesn't Linq to SQL miss the point? Aren't ORM-mappers (SubSonic, etc.) sub-optimal solutions?

I'd like the community's take on some thoughts I've had about Linq to Sql and other ORM mappers. I like Linq to Sql and the idea of expressing data access logic (or CRUD operations in general) in your native development tongue rather than having to deal with the "impedance mismatch" between C# and SQL. For example, to return an ObjectD...

Patterns or techniques for designing a flexible advanced search with Linq Expression Trees

I'm looking to add an "advanced search" capability to my ASP.NET/SQL Server 2005 application. Ideally, I'd like it to be table driven. For example, if my schema changes with the addition of a new column to a table that I want to search, I'd like to have the UI reflect the addition of the new column as a searchable field. I can envisio...

How do I delete an object from an Entity Framework model without first loading it?

I am quite sure I've seen the answer to this question somewhere, but as I couldn't find it with a couple of searches on SO or google, I ask it again anyway... In Entity Framework, the only way to delete a data object seems to be MyEntityModel ent = new MyEntityModel(); ent.DeleteObject(theObjectToDelete); ent.SaveChanges(); However,...

LINQ to Entities and creating a new instance of an entity

I am trying to create a new instance of a Customer entity in our application, and I am having a few problems. This entity has several navigational properties, each of which has their own nav. properties. For example, each Customer entity has an Address entity, and each Address entity has a Phone Number entity etc. I haven't figured ou...

concurrent SqlConnection and EntityConnection to a local Sql Express Server

I'm using Linq2Entity for most of my database operations. However for database creation, table creation and initial data insertion I use plain SQL files. Therefore I need both an SqlConnection and an EntityConnection. Unfortunately the Entity Framework starts complaining that the Sql Server is not listening on the other end of the pipe. ...