entity-framework

How can I save a foreign key using Entity Framework?

Hi guys, first some background. Here is the SQLite script I created: create table Person( ID integer not null primary key autoincrement, Name text not null ); create table Department( ID integer not null primary key autoincrement, Name text not null, Leader integer not null references Person(ID) ); It generates the following Entity F...

Generate a complex database model with MS Entity Framework

I have a database with about 160 tables (it's a shock ! I thought it had about 50...). We use a codebase with no DAL, and we want to start using MS Entity Framework (that's the latest, hottest thing in .net DAL, right ?) so we can use Linq and other state-of-the-art-3-years-ago stuff. I tried to automatically generate the whole DB model...

Where should I create my Entity Framework context object in an MVC app?

I would like to use the Session-per-request pattern, as is done frequently when using NHibernate in an ASP.NET environment. My first thought was to put the code to create the context in the BeginRequest event handler in Global.asax, but I discovered that this event is firing not only for the initial request that actually does the work...

Trouble with saving a combobox value with Entity Framework.

This question is pretty simple, but I'm not seeing why the code isn't working? Here's how I set the members of a ComboBox I have on my form: private void LoadUsersToComboBox() { ScansEntities3 db = new ScansEntities3(); comboBox1.DataSource = db.People; comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "ID"; } ...

Are there uses for TransactionScope in Entity Framework 4 in situations that do not span multiple context objects?

I am working on my first large project that uses EF4 and have been pondering concurrency situations as I am implementing certain business scenarios. I understand that EF has built in support for optimistic concurrency by setting Concurrency Mode to Fixed on entity properties. This seems to be sufficient in most cases. Several things I...

Entity Framework compare generic

It is known generics do not support equality comparing if "class" restriction is not applied to a parameter. How can we workaround it for LINQ To Entities? query.Where(p => p.CategoryId == categoryId); //doesn't work The workaround I saw before was to use EqualityComparer.Default.Equal, but it can't be translated to SQL. I also tried...

EF Where(x => x.ColumnVal == 1) vs FirstOrDefault(x => x.Column == 1)

I had a LINQ query that loads a hierarchy of objects like the following. Query #1 var result = db.Orders .Include("Customer") // many other .Include() here .FirstOrDefault(x => x.Customer.CustomerId == 1 && x.OrderId == orderId); I was having MAJOR perfo...

MVC Entity Framework connection string error

What are the possible reasons for getting this error: "The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid." I am using the auto-generated connection string that the EF Wizard created and added to my app.config, so I would think it should work? ...

EF4 Object State Manager is claiming multiple entries are attached when there aren't

I am trying to add functionality in my ASP.NET MVC app to change some fields of my data structure. After clicking the submit button on the form, the following action is called: [HttpPost] public ActionResult Edit(Document doc) { // Attempt to save the project if (_documentService.SaveDocument(doc) == Service...

Concise XML from EntityObject through WCF?

I'm rather new to WCF and the Entity Framework, so bear with me. I'm passing objects generated by the Entity Framework through a WCF service, and I want to be able to access said objects with both SOAP and REST. What I have currently works, but the outputted XML seems far more bloated than it needs to be. Here's an example response from...

Entity Framework POCO generator vs Entity names

Poco generator for EF 4 is great! it took me a while to figure out how to use my existing classes as POCO's but i did and it works. One thing i can't seem to still be able to figure out, is how to use the same class for 2 entities. Seems that the POCO class has to have the same name as the Entity it is going in place of, and not ju...

EF POCO - Unable to infer a key for entity type?

I have a POCO class, mapping to a table that basically contain three primary keys as follow: public class ContactProjectSite { public int ContactID { get; set; } public int ProjectID { get; set; } public int SiteID { get; set; } public virtual Contact Contact { get; set; } public virtual Proj...

What is the best book or study material to study POCO in asp.net?

What is the best book to study Plain Old CLR Object (POCO) in .NET? ...

Setting the seed value for an identity column in visual studio/entity framework w/SQL Server 2008R2

Is it possible to override the seed value when creating a new table using the designer in visual studio? I know it does not really matter from a programmatic point of view, but I don't like when ID's start at 1. I don't want to see customer ID of '1' or a sales order of 3 - I prefer them to all be the same length - i.e. 4 or 5 or 6 di...

ASP.NET MVC Add Child Records Dynamically

Using the Entity Data Framework, I have a model defined called Client which simply contains an id and a name. I then have an association with another model called Appointment containing an id and a date. For the form, I wish to allow users to create a new client and on the same form, add appointments (before the client is created). I ha...

Should I use the entity framework or linq to sql for new mvc project?

I have a new project where I want to use MVC (I will be learning as I code), and I have never used linq or entity (or mvc). Which should I use? Does it matter? edit: I will be having a lot of different databases, from Oracle to FoxPro. ...

Serializing Entity Framework problems

Like several other people, I'm having problems serializing Entity Framework objects, so that I can send the data over AJAX in a JSON format. I've got the following server-side method, which I'm attempting to call using AJAX through jQuery [WebMethod] public static IEnumerable<Message> GetAllMessages(int officerId) { SIBSv2Enti...

Entity Framework 4, MOQ,

Hi, I am using EF4, Microsoft.Entity.CTP, and the latest MOQ. I am trying to create a generic repository class and moq the DBContext using MOQ. Whenever I run my moq test I get "object reference not set to an instance of an object" on this.context.Set().Add(entity); and I don't understand why. The code runs ok without a moq. public clas...

If you generate a database using EF, do you also use EF to manage the database?

"Manage" as in, make changes to the tables. If yes, how does this work with multiple developers and multiple copies of the database (for development/production)? ...

About serilalize the object having generic type in WCF

I implemented a generic way to get the object by id from Entities defined in Entity Framework. But the problem is the object I got has a very weird type like this {System.Data.Entity.DynamicProxies.MyEntity_C71732021C3A9D6A58BDB6087D29E98CFDE09DA9D53AF0892AFB7918AEF7E61F} And WCF will fail when serialize this object as the type of MyE...