entity-framework

False Duplicate Key Error in Entity Framework Application

I have an ASP.NET application using an entity framework model. In an import routine, with the code below, I get a "Cannot insert duplicate key" exception for AccountNum on the SaveChanges call, but when execution stops for the exception, I can query the database for the apparently duplicated field, and no prior record exists. ...

Hiding a passwordhash field in EntityFramework

Im using entity framework for a project and wishes it to behave in similiar way as my normal ado.net-project, where I never fetch the password hash from the database to avoid security leaks of secret information. I´ve though of a couple of ideas one is to hide the field from partial class but I don't know if that is possible. Change ...

IEditableCollectionView.AddNew() Throwing ArgumentNullException

In the context of Silverlight RIA using DomainContext and, the code as follows: private void AddProductButton_Click(object sender, RoutedEventArgs e) { var target = (Web.LocatorProduct)((IEditableCollectionView)ProductSource.DataView).AddNew(); target.Locator = LocatorID; target.Product = NewProduct.Text....

Entity framework memory leak after detaching newly created object

Hi, Here's a test: WeakReference ref1; WeakReference ref2; TestRepositoryEntitiesContainer context; int i = 0; using (context = GetContext<TestRepositoryEntitiesContainer>()) { context.ObjectMaterialized += (o, s) => i++; var item = context.SomeEntities.Where(e => e.SomePropertyToLookupOn == "some property").First(); conte...

Entity Framework 4, Self Tracking Entities T4 Template, ApplyChanges() extension method

I am using EF4 and the built in self-tracking entities template to generate my entites from my model. I also modifeid the T4 template so that all of the references to "ObjectContext" were changed to "IObjectContext", and I applied an interface to the auto generated context (all this was for testing and mocking purposes). //my interfa...

Entity Framework and differences between Contains between SQL and objects using ToLower

I have run into an "issue" I am not quite sure I understand with Entity Framework. I am using Entity Framework 4 and have tried to utilize a TDD approach. As a result, I recently implemented a search feature using a Repository pattern. For my test project, I am implementing my repository interface and have a set of "fake" object data I a...

Why is ExecuteFunction method only available through base.ExecuteFunction in a child class of ObjectContext?

I'm trying to call ObjectContext.ExecuteFunction from my objectcontext object in the repository of my site. The repository is generic, so all I have is an ObjectContext object, rather than one that actually represents my specific one from the Entity Framework. Here's an example of code that was generated that uses the ExecuteFunction m...

StoreGeneratedPattern in Entitiy framework

If the storage model has the StoreGeneratedPattern=identity attribute set, why should not the conceptual model reflect this in some way? Either in and attribute or in a readonly nature of a property? If i need to pass a value to the reference field. ...

Self Tracking Entities with Pre-Generated Views

I am currently using the Self Tracking entities of the .NET Entity Framework, however I would like to speed up my execution of queries. The first thing everyone seems to suggest is generate the views for the model at compile time. Using the ssdl files etc, I was able to create a 'MyModel.Views.cs', which is compiled in my project. Howe...

Extending EF4 SQL Generation

Hi, We're using EF4 in a fairly large system and occasionally run into problems due to EF4 being unable to convert certain expressions into SQL. At present, we either need to do some fancy footwork (DB/Code) or just accept the performance hit and allow the query to be executed in-memory. Needless to say neither of these is ideal and th...

ADO.NET Entity Framework software requirements

Hi, I have .net 3.5 SP1 and VS 2008 SP1 installed in my machine. But what should I further install to create an Entity framework project. Is there any other add ons that is needed? ...

Using DataAnnotations with Entity Framework

I have used the Entity Framework with VS2010 to create a simple person class with properties, firstName, lastName, and email. If I want to attach DataAnnotations like as is done in this blog post I have a small problem because my person class is dynamically generated. I could edit the dynamically generated code directly but any time I ...

how to populate an entity you have extended in the Entity Framework?

I have an entity in my EDMX that I've extended with a few fields in a partial class like this: public partial class Employee { public string JobName {get;set;} } These properties are for display only. In the above example say the entity has a JobTypeID property. I wish JobName to be populated w/ the name that belongs to that J...

Entity Framework - Update entities without Id

I have found many questions here on SO and articles all over the internet but none really tackled my problem. My model looks like this (I striped all non essential Properties): Everyday or so "Play" gets updated (via a XML-file containing the information). internal Play ParsePlayInfo(XDocument doc) { Play play = (from p in doc.De...

Unable to construct an entity (complex) object from a query

Hey, I am very new to entity, sql, c#, and asp.net so this might be something easily fixed. I am attempting to display all the inactive products stored in my table called products in a datagrid. var productQuery = from b in solutionContext.Version where b.Product.Name == search && b.Product.ActiveNumber > b.VersionNu...

Entity Framework 4 Self Many-To-Many with Properties

UPDATE: Solved by myself. Tricky but works. If you know a better solution, feel free to correct me. DESIGNER: CODE: Product product1 = new Product{key = "Product 1"}; sd.AddToProducts(product1); Product product2 = new Product{key = "Product 2"}; sd.AddToProducts(product2); Product product3 = new Product{key = "Product ...

Entity Framework 4 mapping fragment error when adding new entity scalar

I have an Entity Framework 4 model-first design. I create a first draft of my model in the designer and all was well. I compiled, generated database, etc. Later on I tried to add a string scalar (Nullable = true) to one of my existing entities and I keep getting this type of error when I compile: Error 3004: Problem in mapping fra...

Entity Framework 4 with Existing Domain Model

Hi, Im currently looking at migrating from fluent nHibernate to ADO.Net Entity Framework 4. I have a project containing the domain model (pocos) which I was using for nHibernate mappings. Ive read in blogs that it is possible to use my existing domain model with EF4 but ive seen no examples of it. Ive seen examples of T4 code generati...

Entity Framework: table1_table2id mapping to table2_id

Lets say I have two tables like this: person: id, first_name, last_name, phone_id phone: id, phone_number person.phone_id is always equal to a phone.id. Instead of my entity showing person.phone_id, I'd like it to show person.phone_number. How can I accomplish this? ...

Manipulating individual rows of a datagrid

Hey, recently I started working on a webpage that has a datagrid. I understand how to add datasources and that sort of thing, or at least I am starting to get it. But my question is about manipulating individual rows or cells. Is that only possible during the databind event handler, that is the only place I have been able to do it so far...