code-first

Entity Framework 4 - TPH Inheritance in Features CTP5 (code first) with “IS NULL” discriminator

谁说胖子不能爱 提交于 2019-12-31 04:57:05
问题 Hey guys, I'm trying to create a TPH mapping on a hierarchy where the discriminating clause is the classical "IS NOT NULL" / "IS NULL" case. Here is the example, database wise: CREATE TABLE info.EducationTypes ( ID INT NOT NULL PRIMARY KEY, Name NVARCHAR(64) NOT NULL, FKParentID INT NULL REFERENCES info.EducationTypes(ID) ) the idea is to have a class hierarchy like the following one: public abstract class EducationType { public int ID { get; set; } public string Name { get; set; } } public

EF4 Code First - How to properly map Splitting an Entity Across Multiple Tables

帅比萌擦擦* 提交于 2019-12-30 09:39:15
问题 I am using EF4 CTP5 to try to persist a POCO object that is split among two tables, the link being the ContactID. When i save a contact, i want the core contact information saved in one table (Contacts), and the link to the user who owns the contact saved in another (UserToContacts). I have the custom mapping defined below, but when I SaveChanges, i get the following error: A value shared across entities or associations is generated in more than one location. Check that mapping does not split

EntityFramework CodeFirst: CASCADE DELETE for same table many-to-many relationship

旧街凉风 提交于 2019-12-30 04:28:07
问题 I have an entry removal problem with the EntityFramework and a many-to-many relationship for the same entity. Consider this simple example: Entity: public class UserEntity { // ... public virtual Collection<UserEntity> Friends { get; set; } } Fluent API Configuration: modelBuilder.Entity<UserEntity>() .HasMany(u => u.Friends) .WithMany() .Map(m => { m.MapLeftKey("UserId"); m.MapRightKey("FriendId"); m.ToTable("FriendshipRelation"); }); Am I correct, that it is not possible to define the

Entity Framework | Code First | Mapping of sub property from CultureInfo.Name

ε祈祈猫儿з 提交于 2019-12-29 06:35:10
问题 I've got an entity like this : public class Course { public CultureInfo Culture {get; set;} : } And I want to map just the Name property of CultureInfo to a single column in the table that Entity Framework generates for me. How would I go about this? Currently I've tried looking at the OnModelCreating() method of the DbContext, but I'm not finding anything that is standing out. I'm using Entity Framework 4.1 in and MVC 3 application with a Code First approach. Many thanks. 回答1: Unfrotunatelly

Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

喜欢而已 提交于 2019-12-29 06:34:07
问题 Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns Preferably not using attributes. 回答1: If you're building your entities using the fluent interface rather than using attributes over the properties, you may be able to use the DatabaseGenerationOption class (from EntityFramework.dll, in the System.ComponentModel.DataAnnotations namespace). I've not tested it, but this is what it would look like: modelBuilder .Entity<Foo>()

Deploying database changes with EF 4.1

只谈情不闲聊 提交于 2019-12-28 12:33:10
问题 Does anyone have any best practices around deploying database changes in an EF 4.1 code-first solution? I know MS does not currently support database migrations for EF 4.1, but obviously people are going to need to do this from time to time. Thanks 回答1: Once you deployed database to production you must do incremental changes. It means that before you deploy next version you must prepare two databases in your dev box: Database with DB schema currently deployed in production - you should be

Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist

不问归期 提交于 2019-12-28 03:05:25
问题 I am trying to implemente code First Migrations with Oracle.ManagedDataAccess 6.121.1.0 provider, but with no success at all. As I am receiving a ORA-code, I am assuming that the connection are been opened successfully. But the Migrations are failing because, maybe, the provider are behaving as a SQL Server, instead of Oracle. I think that beacause it is traying to use 'dbo' as default schema. Here is my web.config settings: <configuration> <configSections> <section name="entityFramework"

Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist

百般思念 提交于 2019-12-28 03:05:07
问题 I am trying to implemente code First Migrations with Oracle.ManagedDataAccess 6.121.1.0 provider, but with no success at all. As I am receiving a ORA-code, I am assuming that the connection are been opened successfully. But the Migrations are failing because, maybe, the provider are behaving as a SQL Server, instead of Oracle. I think that beacause it is traying to use 'dbo' as default schema. Here is my web.config settings: <configuration> <configSections> <section name="entityFramework"

EntityFramework SqlQuery does not work with custom mapping (DataAnnotation Column)

心不动则不痛 提交于 2019-12-25 11:36:08
问题 I'm using EF 5.0 (CodeFirst) with VS 2012 and am having trouble making a query using SqlQuery. The problem happens in the mapping between the property name of the entity and the name of the column in the database. My entity (model): [Table("Teste")] public class TesteEntity { [Column("Teste_Id")] public int Id { get; set; } [Required] public bool IsAdministrator { get; set; } [Required] public string Name { get; set; } } When I run the query, I get an error. Rotine: List<TesteEntity> list =

EntityFramework SqlQuery does not work with custom mapping (DataAnnotation Column)

痞子三分冷 提交于 2019-12-25 11:36:05
问题 I'm using EF 5.0 (CodeFirst) with VS 2012 and am having trouble making a query using SqlQuery. The problem happens in the mapping between the property name of the entity and the name of the column in the database. My entity (model): [Table("Teste")] public class TesteEntity { [Column("Teste_Id")] public int Id { get; set; } [Required] public bool IsAdministrator { get; set; } [Required] public string Name { get; set; } } When I run the query, I get an error. Rotine: List<TesteEntity> list =