Adding CreatedDate to an entity using Entity Framework 5 Code First

Here is how I did it: [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public DateTime CreatedDate{ get; set; } in my migration’s Up() method: AddColumn(“Agents”, “CreatedDate”, n => n.DateTime(nullable: false, defaultValueSql: “GETUTCDATE()”));

EF5 Getting this error message: Model compatibility cannot be checked because the database does not contain model metadata

I found the code working by changing static LaundryShopContext() { Database.SetInitializer<LaundryShopContext>( new DropCreateDatabaseIfModelChanges<LaundryShopContext>()); } into static LaundryShopContext() { Database.SetInitializer<LaundryShopContext>( new DropCreateDatabaseAlways<LaundryShopContext>()); }

Entity Framework – what is the current command timeout value

From MSDN, CommandTimeout property gets or sets the timeout value, in seconds, for all object context operations. A null value indicates that the default value of the underlying provider will be used. So, if you are not setting it explicitly through code or passing it in your connection string (in MySQL) , then it is … Read more

Entity Framework Code First Using Guid as Identity with another Identity Column

This ended up working for me, Entity Framework 5. Turn off automatic migrations Migrate to create the initial table, no frills Declare the ClusterId as Identity (annotation) [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override int ClusterId { get; set; } Migrate Declare the pk property Id as Identity after the other one has been updated [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override Guid … Read more

Entity Framework: I set the foreign key, SaveChanges then access the navigation property, but it doesn’t load the related entity. Why not?

To ensure that lazy loading of a navigation property will work after you’ve created the parent you must not create the Survey with the new operator but create it by means of the context instance because it will instantiate a dynamic proxy that is capable to lazily load the related Client. That’s what the DbSet<T>.Create() … Read more

How do I specify the maximum column length of a field using entity framework code first

alternatively, you can manually do it on Fluent API use HasMaxLength(450) Configuring Properties and Types with the Fluent API EF 6 EF Core or if you want Data Annotation, use MaxLength and MinLength attributes public class EntityRegister { public int Id { get; set; } [MaxLength(450)] public string Name { get; set; } } Code … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)