linq-to-entities

Why is the SQL produced by LINQ-to-Entities so inefficient?

The following (cut down) code excerpt is a Linq-To-Entities query that results in SQL (via ToTraceString) that is much slower than a hand crafted query. Am I doing anything stupid, or is Linq-to-Entities just bad at optimizing queries? I have a ToList() at the end of the query as I need to execute it before using it to build an XML data...

LINQ to Entity: using Contains in the "select" portion throws unexpected error

I've got a LINQ query going against an Entity Framework object. Here's a summary of the query: //a list of my allies List<int> allianceMembers = new List<int>() { 1,5,10 }; //query for fleets in my area, including any allies (and mark them as such) var fleets = from af in FleetSource select new Fleet { ...

How to display Linq to Entity query result in ASP.NET MVC view

I have a Link 2 Entity query expression in my ASP.NET MVC app: Dim var = From c In context.Evaluation_Template _ From ae In context.Assigned_Evaluation _ Join ua In context.User_Assignment On ae.Assignment_ID Equals ua.Assignment_ID _ Select c.Evaluation_Name, ae.Due_Date, ua.Is_Started, ua.Is_Completed, u...

Noob in linq, selecting the first record of each record with the same value

Hi guys, im trying my best to learn LINQ but im still having a hard time coding it. Like this one, suppose I have a dataset or a List maybe and the names or fields of the of the collection object are the column names. Id | Date |Mon |Tues |Wed |Thu |Fri |Sat |Sun |Count 1 | 01/05 |=1=|==1==|==1=|==1=| 1=|=0=|=0==...

One all purpose (edmx./.dbml) or many depending on a criteria like domain, functionality??

Do you have one gigantic linq to sql DBML or Linq to entities .EDMX file / namespace or many files/namespaces separated logically?? For example in a db schema if you have 3 sub schemas like (Audit and UserMgmt), Human Resource, Sales..would you have them separated? ...

Linq-ToEntities DataSource Assignment Hangs in Winforms

I have a very typical linq-to-entities data binding in WinForms: myGrid.DataSource = myEntities.entity When it reaches that line of code it simply hangs. Similar assignment a different entity work fine elsewhere in the code. The database contains no more than 50 lines of data in all entities (it's a new project) so it's not waiting on...

Instantiating a context in LINQ to Entities

I've seen two different manners that programmers approach when creating an entity context in their code. The first is like such, and you can find it all over the MSDN code examples: public void DoSomething() { using TaxableEducationEntities context = new TaxableEducationEntities()) { // business logic and whatever else ...

Why Linq to Entities is more "hard" that Linq to SQL

Why in Linq to Entities do I need to specify relationships with Include(string)? Linq to SQL doesn't need to. Is this a choice of developers or limitation? Another problem, Linq to SQL is more "POCO" class, Linq to Entities is too complex. ...

How do I update an object's foreign key value with LINQ to Entities?

Suppose I have these tables: Fruits - FruitID INT PK - FruitName NVARCHAR(30) - FruitStatusID INT FK: Statuses Statuses - StatusID INT PK - StatusName NVARCHAR(30) How do I update both the Fruit's name and its status in the database in these situations?: Update a piece of Fruit that came from a previous L2E c...

Why does my Linq Where clause produce more results instead of less?

Hi, I just had the weirdest debug experience in a very long time. It's a bit embarassing to admit, but it lead me to be believe that my Linq query produces MORE results when adding an additional Where clause. I know it's not possible, so I've refactored my offending function plus the unit test belonging to it into this: [Test] public...

Resources for learning LINQ?

I'm looking to learn LINQ, but I'm finding that there is a lot more to it then what I initally expected. In fact, there's so much that I'm not sure where is the best place to start. I know that there's LINQ to SQL, and LINQ to Entities, and a number of other LINQ whatevers out there. Which is the best to start with? It seems that I see ...

How to do SQL Like % in Linq?

Hello All, I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organizations O JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId where OH.Hierarchy like '%/12/%' The line I am most concerned with is: where OH.Hierarchy like '%/12/%' I have a column that stores the hierarch...

LINQ to Entities Entity Initialization

In the tutorials for ASP.Net MVC, the LINQ to Entities code looks like: public class MyController : Controller { private Models db; public ActionResult Index() { db = new Models(); var foo = (from f in db.foo select f).ToList(); return View(foo); } } I'm guessing this has something to do with t...

Three-Tier architecture and LINQ to Entities

Hello all, For a couple of years, I've been using the three-tier architecture (Presentation, Logic and Data Layer) to write applications. Usually, I am using tools such as .netTiers to generate the data layer and partially the logic layer. Everything is well defined and I love it. I am now constraint to use LINQ to Entites (it appears...

Selecting an entity doesn't subselect associated entities

I'm learning ASP.NET MVC (and MVC in general) and all the help online I find only demonstrates using a single table, not relations between multiple tables. I'm running a query that I expect should also return associated entities, but it's not and can't figure out what I'm missing. I appreciate your help! I have the following data: Ti...

Entity Framework: What negatives can I bump into by not disposing of my object context?

EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been tossing around this idea for some time wondering what bad could happen by not properly disposing my object context and allowing it to die with the GC. Normally, I would shun this, but there is a valid reason to do it. We are using partial clas...

Linq to Entities - Sql "IN" clause

Hey guys, In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights IN ("Admin", "User", "Limited") How would you replicate that in a Linq to Entities query? Is it even possible? Thanks! ...

Linq Evaluate Nullable types in select clause

Hi, I get a weird exception: "Unknown Expression type: IIF(e.Accredited.Value, 1, 0)" running the following statement: var x = from e in _EntityManager.TrainingCourses select new { Disabled = (e.Accredited.Value ? 1 : 0) }; Please help!! How do I evaluate a (bool?) in the select Thanks ...

Bulk-deleting in LINQ to Entities

Is there any way to bulk-delete a bunch of objects matching a given query in LINQ or LINQ-to-Entities? The only references that I can find are outdated, and it seems silly to iterate over and manually delete all objects I wish to remove. ...

Entity Framework: Many To Many Count and Sum

I am using the Entity Framework. I have a many to many relationship Articles <-> Categories. Each article can belong to many categories, and each category can belong to more than one article. I can get the COUNT of articles within each category: public IEnumerable<MenuCategory> GetMenuCategories() { return (from c in db.CategorySet...