code-first

WCF - contract-first vs. code-first - how to document easily / properly?

Folks, I'm facing this problem here: I'm designing my second larger batch of WCF services which external parties will consume. For the first batch, I used a strict "contract-first" approach: manually created the WSDL and XSD files, and from those, generated my service and data contracts and implemented my WCF service. Worked ok, I was...

Using Entity Framework 4.0 with Code-First and POCO: How to Get Parent Object with All its Children?

I'm new to EF 4.0, so maybe this is an easy question. I've got VS2010 RC and the latest EF CTP. I'm trying to implement the "Foreign Keys" code-first example on the EF Team's Design Blog, http://blogs.msdn.com/efdesign/archive/2009/10/12/code-only-further-enhancements.aspx. public class Customer { public int Id { get; set; publi...

Where is EntityConfiguration in EF4 VS 2010 RTM?

I cannot find EntityConfiguration. The same question for RC was here but I thought that it would make it to the RTM version. Is it there? ...

Are there any good resources for developing Entity Framework 4 code-first?

I am trying to convert my model-first project to code-first, as I can see dealing with the models with the graphical designer will become hard. Unfortunately, with all my googling I can't find one good reference that describes how to do code-first development. Most resources are out of date (so out of date they refer to it as code-only...

Does EF 4 Code First's ContextBuilder Dispose its SqlConnection?

Looking at Code First in ADO.Net EF 4 CTP 3 and wondered how the SqlConnection in their walkthrough is disposed. Is that the responsibility of ContextBuilder? Is it missing from the example? var connection = new SqlConnection(DB_CONN); var builder = new ContextBuilder<BloggingModel>(); var connection = new SqlConnection(DB_CONN)...

Entity Framework 4 Code First and the new() Operator

I have a rather deep hierarchy of objects that I'm trying to persist with Entity Framework 4, POCO, PI (Persistence Ignorance) and Code First. Suddenly things started working pretty well when it dawned on me to not use the new() operator. As originally written, the objects frequently use new() to create child objects. Instead I'm usin...

Many-To-Many Relationship in Code-First EF4

How do you represent a many-to-many relationship in the EF4 Code-First CTP3? For example if I have the following classes: class User { public int Id { get; set; } public string Name { get; set; } public ICollection<Profile> Profiles { get; set; } } class Profile { public int Id { get; set; } public string Name { ge...

Using MySql with Entity Framework 4 and the Code-First Development CTP

I thought I'd experiment a bit with Scott Guthrie's latest post on code-first dev with Entity Framework 4. Instead of using Sql Server, I'm trying to use MySql. Here are the relevant parts of my web.config (this is an Asp.Net MVC 2 app): <connectionStrings> <add name="NerdDinners" connectionString="Server=localhost; Databas...

Entity Framework 4 Code First Custom table mapping Fluent API issue

First some brief background: I have an existing ASP.NET MVC 1 application using Entity Framework v1 which works fairly well, though because there are getting on to 40 tables the .edmx is getting unwieldy and prone to corruptions with the Visual Studio 2008 designer. What I want to do is to see if it's feasible to migrate the DAL to use ...

Entity Framework 4 Code-First pros and cons

Hi, I would like to know the pros and cons of using EF4 Code-First approach. Can we duplicate all features that EF4 generated classes offer like Lazy Loading, loading related entities, etc? Thanks ...

Code-First Entity Framework - error creating SQL CE DB

I have been using Entity Framework CTP with Code-First as in this tutorial by Scott Guthrie and another by Scott Hanselman (can't post the link, but google "Simple Code First with Entity Framework 4 - Magic Unicorn Feature CTP 4"). This is working perfectly for the main MVC application, but I am now trying to add a testing project, that ...

How do I map collection for non primary key in Entity Frame 4.0 Code First CTP4?

I am having problems trying to map an existing legacy database. In this example a Country has many Cities. The problem is the foreign key on the City table is not the primary key of the Country table Table Definitions CREATE TABLE [dbo].[CD_Country]( [Id] [int] IDENTITY(1,1) NOT NULL, [Code] [char](2) NOT NULL, [Name] [nvarchar](50...

Entity Framework 4 - Code First not storing inherited table separate from base table

With EF Code First CTP 4 I've created a simple project. This project consists of 2 classes, one inherited from other. I wish to store the data in separate tables, but the default of EF 4 is to map/store these two entities in the same table. With .ToTable(), I can change this behavior, but with this I have a side effect: when I persist ...

Entity Framework CTP4 - Foreign key mappings across schemas don't work properly. Bug?

I'm having an issue with tables that have foreign keys to other tables in a different schema. For example, TableA in SchemaA has a foreign key to TableB in SchemaB. When CTP4 creates the database, instead of creating a foreign key from TA to TB, it creates a third table "TableA_TableB" with columns TableA_ID and TableB_ID as if it think...

Domain Modeling Question

The site I am working on has the concept of a User and a Site. A User can join the global site and create mini sites within (www.globalsite.com/minisite). The Users can also Follow other mini sites created by other users. Think about it like if Twitter allowed you to join with one set of credentials and create different accounts, one for...

Entity Framework CTP4 non-standard primary key name usage in BaseEntity

I am struggling already several days to solve my problem with primary key usage. Please, someone help me to solve this puzzle!!! I am using Entity Framework with CTP4 using Code First approach. I adopted for my project Repository pattern published by Huyrua see here. I am very exited with this patern and with CTP4 possibilities in parti...

EF code first - composite key

Hi, I have a legacy database which has two collumns and I want to map them as 1 ID is this possible for example public class Product { public string ProductID {get;set;} public string ShortDescription {get;set;} public string UserName {get;set;} } then my Modelbinder looks like this modelBinder.Entity<Product>(). HasKey(p=>p.P...

Code First Entity Configuration ToTable Problem

If I specify ToTable in the OnModelCreating override like so: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Team>() .MapSingleType() .ToTable("my_teams"); } it creates dbo.my_teams, however if I separate it out into classes like so: public class TeamMap : EntityConfiguration<Te...

Relationship Mapping in EF4 code-only CTP (when using inheritance?)

Hi Everyone, I'm producing a simple composite patterned entity model using EF4 w/ the code-first CTP feature: public abstract partial class CacheEntity { [Key]public string Hash { get; set; } public string Creator { get; set; } public int EntityType { get; set; } public string Name { get; set; } public string Predec...

Navigation Property Null after query in CTP4 Code First EF4 Feature

Hi, I just started playing around with the CTP4 and Code-First. I have the following setup for a possible dating site: public class User { [Key] public int Id { get; set; } [Required] public string LoginName { get; set; } [Required] public string Firstname { get; set; } [Required] public string Lastname {...