linq-to-entities

How do I put business logic in my ADO.NET Entity Framework classes?

I'd like to use the ADO.NET Entity Framework for data access, extend its objects for my business logic, and bind those objects to controls in my UI. As explained in the answers to another question, I cannot extend ADO.NET Entity Framework objects with partial classes and use my custom methods in LINQ queries. I don't want methods sho...

Entity Framework & LINQ To SQL - Conflict of interest?

I've been reading on the blogosphere for the past week that Linq to SQL is dead [and long live EF and Linq to Entities]. But when I read the overview on MSDN, it appeared to me Linq to Entities generates eSQL just the way Linq to SQL generates SQL queries. Now, since the underlying implementation (and since SQL Server is not yet an ODB...

LinqToEntities not retrieving child objects of an entity

Hi guys, I'm trying out Linq for the first time and having a bit of difficult retrieving the child objects of an entity. I have a course table which has a one to many relationship with the department table (ie. one department can have one or many courses). When I select the a particular department I want to bind the courses relating ...

Entity framework: One big model or a set of smaller models?

We been having some discussions on approaches to using the entity framework at work recently. We have a fairly large and complex n-tier web based application, which is due for a major overhaul. The question is: If we where to starting using the entity framework, would it be better to create one big model, or a set of smaller functional/...

Linq to Entities and concatenated properties

Hi, Does anyone know if its possible to create a new property on an existing Entity Type which is based on 2 other properties concatenated together? E.g. My Person Entity Type has these fields "ID", "Forename", "Surname", "DOB" I want to create a new field called "Fullname" which is Forenames + " " + Surname So i end up with "ID",...

Locating the getter and setter access modifiers in the EdmItemCollection of Entity Framework

I've been creating a nice T4 template for a repository pattern for my entities. Instead of manually parsing the xml in the edmx file I use the EdmItemCollection to create a object graph presentation for the conceptual model. I've been able to get a lot of information out of this model. But I cant find where to locate the Getter and Sett...

How do I get the max ID with Linq to Entity?

I have a table User which has an identity column UserID, now what is the correct Linq to Entity line of code that would return me the max UserID? I've tried using (MyDBEntities db = new MyDBEntities()) { var User = db.Users.Last(); // or var User = db.Users.Max(); return ...

How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load().

I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it) and I'm writing a lot of code like this: var item = (from InventoryItem item in db.Inventory where item.ID == id select item).First<InventoryItem>(); and then calling methods on that object like this: var type = item.ItemTypeRe...

Optimize Group By in LINQ to Entities

I have this query in LINQ to Entities. var query = (from s in db.ForumStatsSet where s.LogDate >= date1 && s.LogDate <= date2 group s by new { s.Topic.topicID, s.Topic.subject, s.Topic.Forum.forumName, s.Topic.datum, s.Topic.Forum.ForumGroup.name, s.Topic.Forum.forumID } into g ...

how to translate the SQL code "having" condition into LinqToSQL or LinqToEntites?

Could you tell me how to translate the following SQL code to Linq To SQL or Linq To Entites? The correst SQL code is: select CollectId,url,userid,pubtime from Collect group by url,collectid,userid,pubtime having pubtime >= (select max(pubtime) from collect d where d.url = collect.url ) order by Collect.pubtime desc Th...

How to customize an Execute method of ObjectQuery?

I have a partition-like database schema in my database. There's one 'partitioning' table named SITE and every other table has a foreign key to that table (SITE_FK). I wrote a partial class for an ObjectContext adding a SITE_ID property and a constructor that sets this property. Now, after I instantiate an ObjectContext with some SITE_I...

LinqToEntities and Foreign Keys

I'm trying to use LinqToEntities and just noticed that there are no foreign key fields in the data model. That seems to cause some trouble when trying to add a record. Reading around I found that when adding a record you can do something like this (Product has a foreign key to the Categories table). Product myProduct = new Product(); ...

How do you do a SQL style 'IN' statement in LINQ to Entities (Entity Framework) if Contains isn't supported?

I'm using LINQ to Entities (not LINQ to SQL) and I'm having trouble creating an 'IN' style query. Here is my query at the moment: var items = db.InventoryItem .Include("Kind") .Include("PropertyValues") .Include("PropertyValues.KindProperty") .Where(itm => valueIds.Contain...

Linq to Entities, Table per Type and Nullable Foreign Key Relationships.

Hey, I'm using Linq to entities applying a Table per Type approach. This has been going very well, up to now. I have the following setup: Parent Table Child Table (Inherits from parent) Grand Child Table (Inherits from Child Table) Linking Table (Has Foreign Key Nullable, to Child Table) Here is the database diagram Following the...

LINQ To Entities and Lazy Loading

In a controversial blog post today, Hackification pontificates on what appears to be a bug in the new LINQ To Entities framework: Suppose I search for a customer: var alice = data.Customers.First( c => c.Name == "Alice" ); Fine, that works nicely. Now let’s see if I can find one of her orders: var order = ( from o in alic...

Entity Framework, building query based on criteria

I was wondering if anyone had a better idea how to do this. atm returning IQueryable<Member> as ObjectQuery<Member> seems dirty to me. namespace Falcon.Business.Repositories { using System; using System.Data.Objects; using System.Linq; using Falcon.Business.Criteria; using Falcon.Business.Entities; using Falcon.B...

Are LinQ Queries above different LinQ providers possible?

I'm currently thinking about a repository pattern for my data objects, where multiple IQueryable<> instances can be registered as data sources. But it seems its not so easy to get it running :-) Running a simple LinQ Query with Linq to entities and linq to objects doesnt work. Do you think this is in general possible? Maybe the only sol...

Linq 2 SQL or Linq Entities

I am starting to design a new application and what I am wondering is peoples opinions on Linq2SQL or Linq2Entities and what they feel is the better technology for rapid development. I am also doing some research into ADO.net data services. ...

'Contains()' workaround using Linq to Entities?

I'm trying to create a query which uses a list of ids in the where clause, using the Silverlight ADO.Net Data Services client api (and therefore Linq To Entities). Does anyone know of a workaround to Contains not being supported? I want to do something like this: List<long?> txnIds = new List<long?>(); // Fill list var q = from t in ...

Linq to Entities / Entity Framework cross edmx "join"

I have two entities, each from a different database and therefore different edmx files. There is, however, an infered relationship between them. Foo has many Bars for example. What's the easiest way to do this join in the EntityFramework, with fewest database calls? Thanks. ...