linq-to-entities

How do I add a navigation property for a Entity Framework Complex Type

I'm using VS2010 Beta 2, I have a Complex Type called Address with the following properties: Street City CountryId I have a Country Entity defined in my Model, but I can't seem to find a way to add a reference (Navigation Property) from the CountryId property of my Complex Type to the Id property of my Country entity. I'm I going ab...

Using SQRT in a Linq EF Query

I need to use the SQRT function as part of a where clause in a Linq EF query. I figured I could do this: var qry = context.MyTable.Where("sqrt(it.field) > 1"); But it returns an error saying "'sqrt' cannot be resolved into a valid type constructor or function., near function, method or type constructor, line 6, column 5." I had alwa...

Linq-To-Entities Include

I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about eager and lazy loading. proxy.User.Include("Role").First(u => u.UserId == userId) This is supposed to load the User, along with any roles that user has. I have a problem, but I also have a question. It's just a simple model created to learn a...

Does Linq to Entities Cache Queries?

I will be using Linq to Entities. The question that I have is, I will be calling Linq to Entities multiple times. Will Linq to Entities queries be cached will it is called several times? If not is there a way to cache the query so it is not compiled or generated every time it is called. ...

Linq To Entities question

Hi there, I have a table called TableA whch has a foreign key from TableB and a one to many relationship to TableB I want to do: var v = Context.TableASet .Include("TableB") .Where(x => x.TableB.Col1 == 123) But when I do x.TableB. I don't have the Col1 option. this is because TableB has a one to many...

Linq to Entities: Mixed graph of Entities, EntityKeys, Attached, and New Objects

In my data model I have a fairly common division between my objects/tables/data: "Transactional" entities that represent the work that is being done by the system. These entities are created by the system and are only important in specific contexts. They are regularly created on the fly. (Aside: Is there a proper name for this type of ...

Having troubles loading related entities (Eager Load) with ObjectContext.CreateQuery (Entity Framework and Repositories)

Here's a bunch of things I tried... hopefully you can extrapolate from it what I'm trying to do and what I'm doing wrong. Okay so I'm having problems with loading related entities when using this DoQuery: public ObjectQuery<E> DoQuery(ISpecification<E> where) { return (ObjectQuery<E>)_ctx.CreateQuery<E>("[" + typeof(E).Nam...

Dynamic entity in EF1/change model in runtime/add property dynamicaly

Hello all I want to give users the possibility to dynamically add new columns at the runtime. I am using the Entity framework v1 ... I did manage to read as xml and then change ssdl , csdl and msl files and construct new workspace and new object context... But the problem is when i dynamically add new columns in EF model the underlying...

Entity Framework - Include in sub query?

I'm not sure if this has been answered yet, I looked at a couple of questions but I don't think they were quite what I was after. Let's say I have 3 tables: Restaurant 1.....M MenuCategory 1.....M MenuItem I have a L2E query that looks something like this: Restaurant = context.Restaurant .Include(r => r.MenuCategory) .FirstOrD...

Entity Framework - Include in sub query? - Part 2

I'm not sure if this is the right thing to do, I'm sure someone will tell me if it's not. I asked a question (http://stackoverflow.com/questions/1662760/entity-framework-include-in-sub-query) earlier this evening, which was answered very well and has solved my problem. But, I think there could be a better way, so I'm going to re-ask th...

Linq to entities: how to do a subquery

Hi there, How can i do this query with Linq To Entities SELECT * FROM TableA WHERE MyID IN ( SELECT MyID FROM TableB ) The thing is that TableB does not exist as an entity because it contains only foreign keys to other tables, and there is no direct link between TableA and TableB ...

How to relate entities that are not directly mapped through a navigation property

I have an object that has been populated with the contents of four different related entities. However i have another entity in which i cannot include as part of the query due to it not being related in the navigation properites directly to the IQueryable table i am pulling. The entity i am trying to include is related to one of the fo...

LINQ (to Entities) - Filtering items using ints

Using LINQ to Entities, how can I determine if any item from a List of ints exists in a comma delimited string of ints? For example, I want to write something like the following (logically): collection.Where(collection.DelimitedStringOfInts.Contains(listOfInts.AnyOfThem)) Also, I should mention that I'm doing this using LINQ metho...

Linq to Entities and SQL Server 2008 FileStream

Backend: SQL Server 2008 database with FileStream enabled Data Access: Linq to Entities I have thousands of pdf's that currently reside on a file server. I would like to move these pdf's off of the file server and into a SQL Server 2008 database so that I can manage them easier. As a proof of concept (ie - to ensure that the new FileS...

How to relate entities without navigation property mappings

Hi, I Have Database that contains 4 tables TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more cart item fields) TABLE XREFCARTITEMPROMOTION (CART_ID, ITEM_ID, PROMOTION_ID) TABLE TBLPROMOTION (PROMOTION_ID, PROMOTION_TYPE_ID, many more promotion fields) TABLE LKPROMOTIONTYPE (PROMOTION_TYPE_ID, PROMOTION_TYPE_DESCRIPTION)...

LINQ to Entities / SQL - Way of seeing what is attached to object context?

Bit of an odd question but is there a way of seeing what objects are attached to my object context. I am getting a few random problems and it would really be helpful to solve them if i could see what's been attached and not yet saved through "SaveChanges". Answer (Entity Framework) : context.ObjectStateManager.GetObjectStateEntries(Enti...

C# - code against a property using the property name as a string

What's the simplest way to code against a property in C# when I have the property name as a string? For example, I want to allow the user to order some search results by a property of their choice (using LINQ). They will choose the "order by" property in the UI - as a string value of course. Is there a way to use that string directly ...

Using linq how do i remove multiple records from a cross reference table

Hi, My Database contains 4 tables: TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more cart item fields) TABLE XREFCARTITEMPROMOTION (CART_ID, ITEM_ID, PROMOTION_ID) TABLE TBLPROMOTION (PROMOTION_ID, PROMOTION_TYPE_ID, many more promotion fields) TABLE TBLITEM (ITEM_ID, many more item fields) The XREFCARTIEMPROMOTION table ...

Linq to entities - searching in EntityCollection navigation properties.

We have classes public Invoice: EntityObject { public EntityCollection<InvoicePosition> Positions { get {...}; set{...}; } ... } public InvoicePosition: EntityObject { public string GroupName { get {...}; set{...}; } } We are given IQueryable<Invoice>, we are not given IQueryable<InvoicePosition>. How should I find invoic...

NullReferenceException on trying to enumerate an empty IQueryable.

I am getting a NullReferenceException when I try and convert the following LINQ to EF query. What could be wrong here? List<DailyProductionRecord> prodRecs = new List<DailyProductionRecord>(); var recs = from p in productionEntities.DailyProductionRecordSet where ((p.Department.DeptId == d...