entity-framework

DefaultIfEmpty but in declarative?

In .Net I have an Entitydatasource (EDS) that populates a gridview. The EDS is bound to the "one" side of a one to many relationship because these are the fields I need to update. I am Eval'ing information from the "Many" side to be displayed in the gridview as well. If a record exists in the "Many" side but the matching record does no...

Using statment and Entity Framework Entities

I'm having a bit of trouble getting my head around when entities are attached and change tracked and when they are not. Sorry if this has already been asked. Say I have some code like this: public MyEntity GetEntity() { using (var ctx = new MyObjectContext) { return ctx.MyEntitySet.First(); } } Then I call it var...

Asynchronous ObjectContext.SaveChanges() ?

Hi all! I want the SaveChanges of the ObjectContext (Win apps) to SaveChanges asynchronously, will show a marquee (or controllable?) progress bar (this I can easily implement) for the user while he is able to continue working. I basically want to override the SaveChanges of the ObjectContext. Has anyone thought about this before? ...

New object in the Entity Framework - problems with primary key

In my database I have a Vehicle table with a primary key. I am creating a new Vehicle object using new Vehicle(); and updating the properties of vehicle appropriately. When I try to do a genesisContext.Vehicles.AddObject(vehicle); The first time the table is successfully updated and the primary key is 0. On all subsequent occassion...

How to upload files larger than 16k to a WCF-service?

To make a long story short: Making a web application Each user profile contains exactly one profile image, which is stored in the database The bottom layer uses ADO.NET entity framework for data access and relationships between classes Inserting images into the database on the bottom data access layer of the application works fine On t...

Getting an error when using ObjectContext.AddObject with Entity Framework

I am getting an error while using the Entity Framework and C#. I am trying to save any generic Entity with a line of code similar to the following: objectContextInstance.AddObject(objectToSave.GetType().ToString(), objectToSave) The error message I receive is: The provided EntitySet name must be qualified by the EntityContainer...

Should I use a composite key for a map table, which is also used for a foreign key?

I am using ASP.NET and the Entity Framework to make a website. I currently have a map table for a many to many relationship between... let's say users and soccer teams. So: Users Teams UserTeams Part 1: Is it best practice to use a composite key for the primary key of the map table? In other words: UserTeams table PK UserId PK Te...

Entity Framework Many To Many CRUD

Hi I am playing around with Entity Framework for a POC project. In my database I have Category<-------CategoryProduct ------->Product (where the join table is an entity in the model). How can I do select/insert/update or delete on this? ...

Entity framework linq to entities

Previously when I wanted obtain related data in an sql query I would join tables, however now in linq to entities I want to get data from a table that is related to the table through another table. I don't know how to perform this sort of query in linq to entities. If someone could help that would be good. The example is a table named p...

attaching an entity with a related entity to a new entity framework context

Im trying to get my head around attaching an entity with a related entity to a new context when I want to update the entity. I have a Person Table (Generalised to Personnel), which has a LanguageID field. This field is linked as a FK via the EF to another table Language with LanguageID as the primary key (1-M). I need to update a partic...

Working with GUIDs and Entity Framework

This question highlights that you can not use server side generated GUIDs with the entity framework. But, I want the generation of the GUID handled at the DAL level of Database API (ie, when an entity's constructor is called, I want the id of the entity to be initialized to a new GUID). My plan is to write a small tool to generate a bu...

Update EntityKey Reference in Entity Framework

I created an application that uses Asp.net, Entity Framework and Windows Workflow Foundation and everything works as expected. My asp.net page should start a Workflow that executes and update an entity passed to the workflow from the page. Everything works ok: i used Unit Of Work pattern to share the context between asp.net and WWF and...

How can I determine if an entity collection contains one of several possible values?

With the .Net Entity Framework and Linq, I'm having a problem finding the best (i.e. easiest to read/understand) way to implement a search for whether or not an entity collection contains any of several possible values. Consider a basic membership/roles implementation, where User has a Roles collection. What would be the "best" way to ...

Dynamic Data with Entity Framework... using [ScaffoldColumn(true)] to show a public property via metadata ...

... it just doesn't work, at all. I've tried for days, with all different combinations of frick'n stuff and it won't budge. There are certainly people out there who seem to be blogging about breezing through this sort of thing without seeing a glimpse of an issue saying things like "We all know that you can show public properties of ex...

Strange Exception thrown using Dynamic Linq Entity Framework Query

I have a gallery entity framework class,and I'm attempting to use the Dynamic Linq Library posted on ScottGu's blog to query the entity set. The failing line of code reads: return context.Galleries.OrderBy(sidx + " " + sord).Skip(page * rows).Take(rows).ToList(); sidx=="Name", and sord=="desc". The Gallery object does have a propert...

Entity Framework Metadata LINQ (Converting from C# to VB.NET)

I've got a query in C# that is working for me to query the metadata for the Entity Framework. I need to convert it to VB.NET, but I'm struggling to convert the AS keyword to "cast" meta to System.Data.Metadata.Edm.EntityType. I've tried TryCast, CType, Cast, etc. Here's the query in C#: var queryResult = from meta in oc.MetadataWorks...

Get types collection from EntityFramewrok ObjectContext

How can i extract list of Types from ObjectContext? e.g., i have object context contains entity named "Bank" and entity named "Company". I want to get the EntityObject type of them. How can i do this? ...

Creating DTOs automatically with Enity Framework (not vs 2010/v4) - with t4?

Anybody know of a good way to create my dtos for use with Entity Framework (not vs 2010 or v4beta) ... I have seen a few examples with t4 but haven't got any to work. Anybody suggest the best route for this, i will of course use autoampper to map between my entities and my dtos but i don't want to create my DTOs one by one ... is so muc...

Entity Framework - SaveChanges() doesn't get the generated Identity key

I'm using entities Framework in my project and it has been a nightmare! I have a SQL DB were I have a table called Form. Form has an ID that is a PK and Identity (it's automatically increased). This time I'm doing this: Dim form as int32 Dim dbform As New Entities1 Dim form696 As New Form dbform.AddToForm696(form) dbform.SaveChanges...

Adding custom property to Entity Framework class

I need to add a custom property to an Entity Framework class, however when I do I get the "The property name XXX specified for type XXX is not valid." error. Is there some attribute I can give the property so it is ignored and not mapped to anything? Edit: If I add a custom property, as per Martin's example below, then the following c...