entity-framework-4.1

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

穿精又带淫゛_ 提交于 2019-11-27 03:39:55
问题 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.

Entity Framework IValidatableObject reference DbContext

断了今生、忘了曾经 提交于 2019-11-27 03:33:46
问题 I'm trying to get EF 4.1 working with Repository, UnitOfWork, separation of entities from EF and validation. I followed this guide to get a nice separation of my POCO entities from the EF model and I'm now following this guide to implement validation (with IValidatableObject). My solution consists of: Contacts.Repository [references EF and Contacts.Entities]: Contacts.edmx ContactsDbContext.cs Contacts.Entities [no references]: Contact.cs (Contacts.Entities.Contact partial class) Contacts

DBContext Added/Attached Event?

时间秒杀一切 提交于 2019-11-27 03:27:28
问题 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! 回答1: 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

Entity Framework code first, isn't creating the database

旧时模样 提交于 2019-11-27 03:22:39
问题 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.

Entity Framework Code First Date field creation

三世轮回 提交于 2019-11-27 03:09:10
I am using Entity Framework Code First method to create my database table. The following code creates a DATETIME column in the database, but I want to create a DATE column. [DataType(DataType.Date)] [DisplayFormatAttribute(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")] public DateTime ReportDate { get; set; } How can I create a column of type DATE , during table creation? The EF6 version of David Roth's answer is as follows: public class DataTypePropertyAttributeConvention : PrimitivePropertyAttributeConfigurationConvention<DataTypeAttribute> { public override void Apply

Composite Key with EF 4.1 Code First

倾然丶 夕夏残阳落幕 提交于 2019-11-27 03:02:10
I am trying to figure out how to have a composite key using EF code First 4.1 RC. Currently, I am using the [Key] Data Annotation, but I am unable to specify more than one key. how would one specify a composite key? Here is my Example: public class ActivityType { [Key] public int ActivityID { get; set; } [Required(ErrorMessage = "A ActivityName is required")] [StringLength(50, ErrorMessage = "Activity Name must not exceed 50 characters")] public string ActivityName { get; set; } } I need the "ActivityName" to also be a key. Sure, I can code around this, but thats not good database design. You

EF 4.1 Code First error - The entity type SomeType is not part of the model for the current context

橙三吉。 提交于 2019-11-27 03:01:45
问题 While working with EF code first I get error given below at different times: The entity type SomeType is not part of the model for the current context. What are the possible causes of this error? 回答1: It may occur because: DbContext configured with an incorrect connection string The entity specified is actually not mapped in configuration 回答2: I got this when my class that inherited from DbContext did not declare the model as a property. For example, I neglected to add a property for FooModel

Get the primary key value of an arbitrary entity in code first

為{幸葍}努か 提交于 2019-11-27 02:47:49
问题 Is there such a method? object GetPrimaryKeyValue(DbEntityEntry entry); Or how should it be implemented? 回答1: You need to cast your DbContext to IObjectContextAdapter so you can access the underlying ObjectContext which gives you access to some more advanced features hidden by DbContext . Inside your class which derives DbContext the following method will work. object GetPrimaryKeyValue(DbEntityEntry entry) { var objectStateEntry = ((IObjectContextAdapter)this).ObjectContext

EF 4.1 OnModelCreating not called

牧云@^-^@ 提交于 2019-11-27 02:39:56
问题 I have a problem with EF 4.1 not calling OnModelCreating so that I can configure tables etc. I have an existing database. Here is my connection string: <add name="AcmeDBContext" connectionString="metadata=res://*/|res://*/|res://*/; provider=System.Data.SqlClient; provider connection string=" data source=[server]; initial catalog=Acme;integrated security=True; multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> Here is my class inherited from

On Insert / Update logic in EF code first

[亡魂溺海] 提交于 2019-11-27 02:18:48
问题 I would like to add some logic to the insert and update events of some EF objects. I have a MVC application with category object which has a property which is a slugified version of the name property. public class Category { public string Name { get; set; } public string UrlName{ get; set; } } I would like to set the UrlName property only on the insert and update events because my slugify logic is quite elaborate. I am aware that I can add some logic inside the SaveChanges() function on the