entity-framework-4.1

EF 4.1 Code First: Why is EF not setting this navigation property?

ぃ、小莉子 提交于 2019-11-28 14:02:56
Here's a sample scenario that illustrates the problem I am having. Here is the DB script to generate the database in SQL 2008: USE [master] GO /****** Object: Database [EFTesting] Script Date: 08/15/2011 09:56:33 ******/ CREATE DATABASE [EFTesting] ON PRIMARY ( NAME = N'EFTesting', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\EFTesting.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON ( NAME = N'EFTesting_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\EFTesting_log.ldf' , SIZE = 1024KB , MAXSIZE

Convert from to string in database to boolean property Entity Framework 4.1

若如初见. 提交于 2019-11-28 13:58:51
i am working on a legacy oracle database that uses character literals T and F in the database for its boolean values however i would like the Entity property to reflect a proper boolen value is there a wy to convert this value when the model is binding it is a read only database so inserts are not important War I would suggest wrapping up or extending the generating type to add this sort of functionality ... entity framework will generate objects that basically match what the data in the database tables looks like so if you have a table called "Contacts" you'll get an object called "Contacts",

Repository Pattern with Entity Framework 4.1 and Parent/Child Relationships

霸气de小男生 提交于 2019-11-28 13:54:59
问题 I still have some confusion with the Repository Pattern. The primary reason why I want to use this pattern is to avoid calling EF 4.1 specific data access operations from the domain. I'd rather call generic CRUD operations from a IRepository interface. This will make testing easier and if I ever have to change the data access framework in the future, I will be able to do so without refactoring a lot of code. Here is an example of my situation: I have 3 tables in the database: Group , Person ,

Entity Framework Code First Case Sensitivity on string PK/FK Relationships

三世轮回 提交于 2019-11-28 12:08:29
I have a fairly simple composite one to many relationship defined using POCO/Fluent API, one column of which is a string. I've discovered that the data in this column in our database is inconsistent in terms of case ie 'abb', 'ABB' - this is our main ERP system and is fed by a variety of sources which are mainly beyond our control. This is leading to problems using EF code first when joining to related tables as the join is silently ignored by EF when the case of PK/FK is different even though SQL Profiler shows the correct SQL being executed and results returned. I'm using WCF so have lazy

Entity Framework cant use the DbContext, model being created

霸气de小男生 提交于 2019-11-28 12:06:00
I am using EF 4.1, and I create a normal EF edmx file. I generate it from a DB. When it's been generated I rightclick and select add code generation item, to generate new classes, and use the DbContext instead. I use the template DbContext generator. Everything works fine. Then I trie to query the context: using (var context = new PasDBEntities()) { var client=context.ClientCompanies.SingleOrDefault(_=>_.ID==clientCompanyId); if(client!=null) I have no problem creating a new instance of the context but when I try to query it the problem occur. I get stuck on the UnintentionalCodeFirstException

Entity Framework mapping

跟風遠走 提交于 2019-11-28 11:37:25
问题 I've made simple classes that simulate the classes I have (sorry I had to make up the classes, the usual example databases do not have the structure I wanted to ask about): public class Animal { public System.Guid ID { get; set; } public string SpeciesName { get; set; } public virtual ICollection<AnimalSpecies> AnimalSpecies { get; set; } } Species Fish: public class Fish { public System.Guid ID { get; set; } public int Freshwater { get; set; } } Spieces Reptile: public class Reptile { public

DBContext Added/Attached Event?

ⅰ亾dé卋堺 提交于 2019-11-28 11:22:24
EF 4.1 RC. I want to run some code after an entity has been added/attached to the DBContext. Is there an event for this (I can't find one). Basically I want to check if the added/attached entity is of a certain interface and if it is, do some stuff with it. Thanks! Unfortunatelly there are no such events available and there are no extension points to add such events. That is in my opition one of the biggest EF failure. The extensibility = zero. The only thing you can do is override SaveChanges and before executing base.SaveChanges use ChangeTracker to get all attached and added entities of

Could not load file or assembly 'MySql.Data, Version=6.3.6.0

荒凉一梦 提交于 2019-11-28 10:33:33
I'm at a COMPLETE loss - I'm having super wierd issues with what I still really dont even understand... I'm running Entity Framework 4.1, MySql 5.xx and my MySql Connector is v 6.4.4 - everything works beatifully locally however whenever I upload to the server I receive: Could not load file or assembly 'MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An unhandled exception occurred during the execution of

Cascade Delete Rule in EF 4.1 Code First when using Shared Primary Key Association

你离开我真会死。 提交于 2019-11-28 10:16:34
I implemented a bidirectional 1:1 relationship based on this answer: Primary /Foreign Key in Entity Framework I define the bidirectional relation this way: public class Student { public virtual int StudentId { get; set; } public virtual Anamnesis Anamnesis { get; set; } . . . } public class Anamnesis { [Key, ForeignKey("Student")] public int AnamnesisId { get; set; } public virtual Student Student { get; set; } . . . } where, Student is the principal entity and Anamnesis it the entity that shares the PK. Now I'd like that the relationship created had a Delete Rule = CASCADE. Actually, the

Entity Framework code first, isn't creating the database

送分小仙女□ 提交于 2019-11-28 09:55:06
Here's an overview of how my solution looks: Here's my PizzaSoftwareData class: namespace PizzaSoftware.Data { public class PizzaSoftwareData : DbContext { public DbSet<Customer> Customers { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<Product> Products { get; set; } public DbSet<User> Users { get; set; } } } According to an example on Scott Guthrie's blog, you have to run this code at the beginning of the application in order to create/update the database schema. Database.SetInitializer<PizzaSoftwareData>(new CreateDatabaseIfNotExists<PizzaSoftwareData>()); I'm running