Command Timeout with Entity Framework 4.1 Code First

I found this solution after another Google search. You can access the ObjectContext for a DbContext by casting this to an IObjectContextAdapter. From http://social.msdn.microsoft.com/Forums/en-ZA/adodotnetentityframework/thread/6fe91a64-0208-4ab8-8667-d061af340994: public class MyContext : DbContext { public MyContext () : base(ContextHelper.CreateConnection(“my connection string”), true) { ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300; } }

How to store double[] array to database with Entity Framework Code-First approach

You can do a thing like this : [NotMapped] public double[] Data { get { string[] tab = this.InternalData.Split(‘,’); return new double[] { double.Parse(tab[0]), double.Parse(tab[1]) }; } set { this.InternalData = string.Format(“{0},{1}”, value[0], value[1]); } } [EditorBrowsable(EditorBrowsableState.Never)] public string InternalData { get; set; }

Entity Framework 4.3 code first multiple many to many using the same tables

Well, EF doesn’t have some kind of word and grammar recognition algorithm which would be required to identify that you (probably) want that User.Residencies and Town.Residents form a pair of navigation properties and User.Mayorships and Town.Mayors form a second pair. Therefore it assumes that you have four one-to-many relationships and that each of the four … Read more

Entity Framework creates foreign key objects instead of using those that are already available

If you don’t use the same context instance to load related entities you cannot simply add them to the new entity and expect that existing records in the database will be used. The new context doesn’t know that these instances exist in the database – you must to say it to the context. Solutions: Use … Read more

Entity Framework Code First and Connection String Issue

For EF Code First you can use ordinary connection string if you are using SQL Server. <add name=”DataContext” connectionString=”Data Source=myserver.com;Initial Catalog=MyDataBase;Persist Security Info=True;User ID=username;Password=password” providerName=”System.Data.SqlClient” />

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()”));

tech