linq-to-entities

C#: access a class property when the property identifier is known as a string

Hi, I'm using LINQ to Entities on a database which structure is not known in advance. I use reflection to retrieve the information, and now have a list of strings with all the table names. Because I use LINQ, I also have the datasource encapsulated in a C# class (linqContext), with each table being a property of that class. What I want...

Load parent and child table in one query linq to entitiy

I have a following tables/classes structure in Linq to entities. Books { bookId, Title } Tags { TagId Tag } BooksTags { BookId TagId } Now I need to write a query which gives me result like this Class Result { bookId, Title, Tags } Tags should be comma separated text from the tags table by joining all three tables. How...

Can't enumerate LinQ results with left join

var itemSet = from item in da.GetList<Models.account>() join file in objFileStorageList on item.account_id equals file.parent_id into objFile from fileItem in objFile.DefaultIfEmpty() where item.company != null && item.company.comp...

Persisting details in Master Detail relation EF4 POCO

Scenario: Entity Framework 4 , POCO templates and Master Detail relation. Lets say I have a master type like this: //partial implementation of master entity partial class Master { public void AddDetail(x,y,z) { var detail = new Detail() { X = x, Y = y, Z = z, }; ...

Using LINQ-To-Entities to Generate Information

I am working on a website where a user can add tags to their posted books, much like is currently done for questions on Stack Overflow. Classes: Books { bookId, Title } Tags { Id Tag } BooksTags { Id BookId TagId } Here are few sample records. Books BookId Title 113421 A 113422 B Tags Id Tag 1 ASP 2 C# 3 CSS 4 VB 5 V...

EF4. Add a object with relationship causes full table select

Ex 1: "autor.ComentariosWorkItens.Add(comentarioWorkItem);" autor.ComentariosWorkItens makes EF4 load all ComentariosWorkItens. Ex 2: comentarioWorkItem.Usuario = autor; Fixup make EF load all ComentariosWorkItens too: private void FixupUsuario(Usuario previousValue) { if (previousValue != null && previousValue.Come...

joining stored proc result with a query linq to entities

Hi Experts, I am working with linq to entities where I have a stored proc which returns an enetity based on some parameters. I can get this result in program. Now I want to join this resultset with similar entity on a common field. my entity Books { BookId, Title } Stored Proc GetFilterBooks(someparam) ( Select * from books wher...

Manual Linq to SQL entity framework mapping

I've been playing with the O/R designer in VS and I was wondering if someone could shed come light on this. I'm used to OR mappers that are largely manual (homegrown and e.g., NHibernate). I don't mind encoding the entity classes myself, since they don't change all that often to begin with, and I have this irrational fear of designers an...

Why can't I insert record with foreign key in a single server request?

I'm tryring to do a simple insert with foreign key, but it seems that I need to use db.SaveChanges() for every record insert. How can I manage to use only one db.SaveChanges() at the end of this program? public static void Test() { using (var entities = new DBEntities()) { var sale = new SalesFeed ...

.Net Entity Framework & POCO ... querying full table problem

I'm attempting to implement a repository pattern with my poco objects auto generated from my edmx. In my repository class, I have: IObjectSet<E> _objectSet; private IObjectSet<E> objectSet { get { if (_objectSet == null) { _objectSet = this._context.CreateObjectSet<E>(); } return _obj...

Entity Framework Custom Query Function

I have an Entity Framework 4.0 Entity Object called Revision w/ Nullable DateEffectiveFrom and DateEffectiveTo dates. I was wondering if there was a short-hand way of querying an object's RevisionHistory based on a particular QueryDate date instead of having to use the following query structure: var results = EntityObject.Revisions.Wher...

If I select from an IQueryable then the Include is lost

The include does not work after I perform a select on the IQueryable query. Is there a way arround this? My query is public IQueryable<Network> GetAllNetworks() { var query = (from n in _db.NetworkSet .Include("NetworkContacts.Contact") .Include("NetworkContacts.Contact.RelationshipSource.Target") ...

Using an existing IQueryable to create a new dynamic IQueryable

I have a query as follows: var query = from x in context.Employees where (x.Salary > 0 && x.DeptId == 5) || x.DeptId == 2 order by x.Surname select x; The above is the original query and returns let's say 1000 employee entities. I would now like to use the first query to deconstruct it and recreate a new query that would...

NHibernate equivalent of LinqToEntitiesDomainService in RIA

Hi, When using Entity Framework with RIA domain services, domain services are inherited from LinqToEntitiesDomainService, which, I suppose, allows you to make LINQ queries on a low level (client-side) which propagate into ORM; meaning that all queries are performed on the database and only relevant results are retrieved to the server an...

LINQ to Entities projection of nested list

Assuming these objects... class MyClass { int ID {get;set;} string Name {get;set;} List<MyOtherClass> Things {get;set;} } class MyOtherClass { int ID {get;set;} string Value {get;set;} } How do I perform a LINQ to Entities Query, using a projection like below, that will give me a List? This works fine with a...

Linq Query with aggregate function

Hello everyone, I am trying to figure out how to go about writing a linq query to perform an aggregate like the sql query below: select d.ID, d.FIRST_NAME, d.LAST_NAME, count(s.id) as design_count from tbldesigner d inner join TBLDESIGN s on d.ID = s.DESIGNER_ID where s.COMPLETED = 1 and d.ACTIVE = 1 group by d.ID, d.FIRST_NAME, d.LAST_...

Entity Framework v2 cache

In EF v1 when we used GetObjectByKey on our context object contrary to linq query it stored queried object in cache is there any change in EF v2 (.NET 4) ? ...

Linq query with aggregate function OrderBy

Hello everyone, I have the following LinqToEntities query, but am unsure of where or how to add the orderby clause: var results = from d in db.TBLDESIGNER join s in db.TBLDESIGN on d.ID equals s.TBLDESIGNER.ID where s.COMPLETED && d.ACTIVE ...

whats the shortest way of returning an Entity Framework object from one table based on it's name attribute?

Hi, what's the shortest way of returning an Entity Framework object from one table based on it's name attribute? So say one had a table person, with column name, what would be the quickest way to return the person object with name = "Tim" say? e.g. context.People.Select(m => m.Name == "Tim") doesn't seem to work? ...

default value support for Entity Framework object construction to avoid having to set this column parameter

Hi, In entity framework is there a way to have a default value for a column such that Linq to Entity won't require this parameter when constructing a new object? For example I've marked on column in the EF designer with a default value (I typed in "All" as it was a string). But if I try to construct a new record and not specify this p...