entity-framework

Entity Framework: Set back to default value

I'm trying to update an entity using a stub. This works fine for changing records, unless I try to set the value back to the default value forr the column. Eg: If the default value is 0, I can change to and from any value except zero, but the changes aren't saved if I try to set it back to zero. This is the code I'm using: var package =...

Generating ADO.NET Entity Data Model files, where to start?

Our product is partially built using Delphi and partially .NET and in our current state of migration to .NET, we have the data dictionary in a Delphi component, so this is the master. From this we generate .NET source code through templating, to support simple querying but also to do Linq2Sql, since our product requires SQL Server. How...

Exceptions in ASP.NET Dynamic Data

I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have just discovered a duplicate key error when attempting a database insert. However, I had to use SQL Profiler to find the error. The insert template page just silently did nothing. How can I trap errors like this and log them and maybe display a message?...

Locking a table with a select in Entity Framework

I need to be able to do select * from myTable with (xlock,holdlock) from Entity Framework. Is this possible? I've opened a TransactionScope with the Serializable isolation level but my selects are not locking the tables. I'd like them to lock until I complete the transaction scope. ...

Is This Normal Development Procedure?

First a little about myself. I am not an experienced software engineer, architect or developer. I have done mostly small ASP and ASP.NET projects in C# for the last 5 years. I am pretty good with HTML and JavaScript. These projects were done when I had free time from my other duties which were not related to software development. I have ...

What design pattern is preferable when working with ASP.Net MVC and Entity Framework?

I am not very sure what design pattern is the most efficent to use when working with ASP.Net MVC and the Entity Framework, so any guidance is much appreciated! Would you store the context in the Controller-class, or is it better to create a repository? If you would recommend the repo-design, is it required to initialize the context in ...

Entity Framework - Contains Method

Someone has an answer to this missing feature in Entity Framework. Does anyone have a solution to the missing Contains method in Entity Framework that works? I've tried a number of those on here and through Google, but none of them seem to actually work. ...

Entity Framework with SQLite

I am trying to create entities out of a SQLite database. SQLite doesnt have foreign keys, therefore I cannot map associations between entities. Is there a way to map them somehow? ...

Connecting to multiple databases in MVC web application

Hey Guys, How to connect to different databases for a .NET MVC web application written in C#? Here the stucture of the database table remains the same. All that changes is the database name. So how to I manually connect to a database or use modify the connection string? The trick is to use the same code. Depending on the URL I want th...

What's wrong with this DataTable while SqlBulkCopy-ing from an Entity?

I know the method below isn't meant to work with any Entity, and its use shouldn't be enforced. I found a System.Data.Linq.Table extension method which uses SqlBulkCopy to insert data. I am trying to adapt it to the Entity Framework but it throws a strange exception, while the original works for Linq-To-Sql data classes. I couldn't find...

Entity Framework/.Net 4.0: POCO and saving many to one relationships

How do I have to set up a property so that when using SaveChanges, the many to one relationship is saved and I don't get the: INSERT statement conflicted with the FOREIGN KEY constraint... error. Pretty simple, I have an Ad and an AdType where there are many Ads to one AdType. There is a property on Ad: public class Ad { public I...

How Can I Detect If An Entity Is Already Attached Using Stub Entities

I want to use stub entities but it seems I cannot use TryGetObjectStateEntry without the full entity? Is there a way to do this with stub entities or any other way to detect if an entity is already attached? AttachTo will throw a InvalidOperationException if I try to attach the same entity twice. I am trying to save a hit to the database...

Entity Framework 4 vs NHibernate

A lot has been talked about Entity Framework first version on the web (also on stackoverflow) and it is clear that it was not a good choice when we already have better alternative like NHibernate. But I can't find a good comparison of Entity Framework 4 and NHibernate. We can say that today NHibernate is the leader among all .NET ORMs, b...

Entity Framework - Update Model from Database - New Column

What is the process I should follow to update my entity framework model when I have simply added a new column to a table in the database? The process that I have followed was to right click within the edmx file and choose "Update Model from Database". Now I can see the new field against the table definition in the Store. But when I l...

Entity Framework - Association Set

I am converting a project from another ORM to Entity Framework. I have a table where all 3 fields are foreign keys. So this table has been automatically mapped as an Association Set. In the previous ORM I could still work with this table as an entity - writing linq statements against it, adding and deleting objects etc. Is it possibl...

How to determine if an Entity with relationship properties has changes

Dim myEmployee as Employee = myObjectContext.Employee.Where("it.EmployeeID = 1").First() The following line will cause e.EntityState to equal EntityState.Modified : myEmployee.Name = "John" However, changing a property that is a relationship will leave e.EntityState = EntityState.Unchanged. For example: myEmployee.Department =...

Repository Pattern and Entity Framework

Hi I looked at lot of examples online using Repository Pattern with EF. But none of them really talked about working with Related Entities. Like say User can have multiple addresses. IUserRepository User CreateUser(); void UpdateUser(); Now if I were to add a Address to the User should, should it be on the Repository? OR on the Use...

Materialize entities from SqlDataReader

Hi Is it possible to materialize (within the Entity Framework) Entities from a standard SQL Data Reader? I am writing specific SQL that is passed to the server using EntityConnection.StoreConnection. Thsi returns a standard Data Reader containing rows should be materialized as Entities. I suppose one workaround is to create a Entity-r...

Problems with char(4) FK, entity framework

Hello I'm having a char(4) FK reltionship, and it gives me lots of errors when I use that in my designer. I have a relation between tables: BookingObjects 1:* IntervalEntities, and it is a char(4) PK in the IntervalEntities table. Error 9 Error 3007: Problem in Mapping Fragments starting at lines 813, 1037: Non-Primary-Key column(...

C# Entity Framework Query...

I'm trying to figure out how to limit my child dataset to only include active records... // Here's what I have currently... m_BackLoggerEntities.Stories .Include("Sprints") .Include("Tasks") .Include("Efforts") .Include("Products") .First(s => s.StoryId == id); // Here's what I thought I could do.....