entity-framework

Imbriqued query with linq to entities

Hello, I'd like to make a query with linq to entities that looks like this : SELECT listid,; itemid,; ( SELECT langs.desc; FROM langs; WHERE langs.langid = 1 AND langs.itemid=l.itemid) as fr,; ( SELECT langs.desc; FROM langs; ...

Eager loading of collection properties during query execution

Is there a way to eagerly load the child collections of entities fetched in a query without having to specify the paths of the collections as strings in the Expand method? Currently I have the following: foo_entities ctx = new foo_entities(new Uri("http://url/FooService.svc/")); ctx.MergeOption = MergeOption.AppendOnly; ...

Entity Framework - Get List of Tables

That's it. It's pretty simple. I've got an edmx and want to be able to dynamically query it for tables and (hopefully), dynamically build against that table. Is that possible? ========= UPDATE: I've included all the DB tables, but no views or SP's, in the context. We have lots of tables that type info (with id's). So, for example...

How do I create a stored procedure with Entity Framework?

I read an old MSDN Forums post about Entity Framework where Julie Lerman stated: wrt Stored Procedures. This is even better than what you are referring to. Not only can you map to sprocs (both in EF and in LINQ to SQL) or override the update/insert/delete methods, but in EF, there is coming a capability to CREATE stored p...

entity framework linq - which should I learn, method-based on query-based?

Just starting getting into Entity Framework and Linq for EF. I'm not sure which of the two query methods I should concentrate on, method-based or query-based? Is there an obvious choice as to which one is easier to use, for both simple and more complex queries, hence should be the one I concentrate on? Assuming I'm using VS2010 does m...

How do I add 'Tags' to my simple BlogPost class library & repository?

Hi folks, Update Checking StackOverflow OData service it's exactly like Posts / PostTags / Tags ... How can I replicate that, please? So I've got a simple class called BlogPost - nothing special. Just a blog post. Now, I wish to add tagging for this class. Exactly like the tags for a StackOverflow question - 5 strings, space delimit...

Entity framework inheritance

I'll try to explain the problem I'm currently facing as simply as possible. The project I'm currently working on is required to analyze some financial data. For convenience, this data should be stored in a database, so I'm tasked with creating a database model. While the database wasn't required up until now, the application itself has b...

Optimistic concurrency model in Entity Framework and MVC

I have the following update code in the ASP.NET MVC controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Person(int id, FormCollection form) { var ctx = new DB_Entities(); // ObjectContext var person = ctx.Persons.Where(s => s.Id == id).FirstOrDefault(); TryUpdateModel(person, form.ToValueProvider()); ctx.SaveChanges(...

Entity Framework book covering CTP4

There are several of books out on EF4. There are large differences between CTP3 and CTP4. The CTP4 came out in July, so is: Pro Entity Framework 4.0 by Scott Klein (Paperback - 15 Mar 2010) Entity Framework 4.0 Recipes: A Problem-Solution Approach (Expert's Voice in .Net) by Larry Tenny and Zeeshan Hirani (Paperback - 19 May 2010) ...

What is an abstract type?

What is an abstract type in context of Entity Framework inheritance? ...

Why is my Navigation Properties empty in Entity Framework 4?

The code: public ChatMessage[] GetAllMessages(int chatRoomId) { using (ChatModelContainer context = new ChatModelContainer(CS)) { //var temp = context.ChatMessages.ToArray(); ChatRoom cr = context.ChatRooms.FirstOrDefault(c => c.Id == chatRoomId); if (cr == null) return null; return cr.ChatMessages.ToArray(); } } ...

How can I bind an entity Data Source to the results of a query

I have a query that will go away an and find data Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray()) Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}" Dim hs As New ObjectQuery(Of v_BillData)(query, CType(Session("ObjectCon"), ObjectContext...

Entities Framework 4 Code First: Large model

Has anyone advice when working with large database models when using EF4 code first? Entity sets are added to the database context, but if I have 100 tables, I need to create 100 DbSets, 1 for each table: public class Customers : DbContext { public DbSet<Customer> Customers {get; set;} public DbSet<Employees> Employees {get; set...

EF 4: Problems understanding DetectChanges when using POCO (no self tracking ObjectContext)

Hi there, I wonder if anyone can help me? I am having problems understanding why i need to issues DetectChanges on my POCO (non proxy) entities. Of course i have this line to ensure that proxies are not returned. context.ObjectStateManager.GetObjectStateEntry(order).State And doing some research it appears if i need to check the...

linq count with join on multiple tables

Let's say I have 3 tables: carts, baskets and eggs where a basket can contain many eggs and where carts contain many baskets. Each basket has a foreign key that maps to a cart and each egg has a foreign key that maps to a basket. I need to return a table that contains these columns: -Cart Name -Number of Baskets in Cart -Number of Eggs...

EF4 Inheritance issues using Table per Type

I'm having quite a bit of trouble trying to get inheritance to work in EF4. The original model is quite large, however I have managed to replicate it in a model of just two entities. Essentially the two tables are "Asset" and "Questionnaire". Questionnaire inherits Asset (i.e. Questionnaire is an Asset). They do this by Questionnaire ha...

Entity Framework change tracking

Is there any way of tracking EF entities changes between contexts for ASP.NET applications? Self-Tracking entities doesn't work well for me as it is primarily designed for WCF. And all approaches for tracking changes for POCO I have found are oriented on shared context. ...

Do Linq to Entities queries *always* hit the database?

My understanding of the Entity Framework is that if it can answer a query from its cache, it will. My simple testing, however, shows repeated queries hit the database even though they were previously answered positively: var u1 = context.Users.SingleOrDefault(u => u.Id == 1); var u2 = context.Users.SingleOrDefault(u => u.Id == 1); Th...

How can i join Master-Detail-Detail Tables with Linq in Entity Framework

I have 3 table a,b and c a.Id,a.code /master b.Id.b.code,b.aId,c.Id /detail c.Id,c.code / detail of detail i will join this three table with linq and show it in grid. How can i do this? ...

Windows applicaton: CRUD operations using linq to entities on datagrid

How do i wrap the linq to entities using c# to a datagrid . I was working earlier on web, so windows is new to me. I have like first name, lastname, phone numbers from a person object i want to display list of persons in datagrid but phone numbers needs to be combo box. Phone numbers are from different table. I get a list of anonymo...