With DevOps bringing source control to configuration files and publishing to production servers being automated – bringing both code and configuration over on the same time, the difference between code and config has become less than ever (if it even exists). A few weeks ago I reread Mike Hadlow’s brilliant post The Configuration Complexity Clock.… Continue reading Code or Configuration or Configuration in Code?
Tag: EF Code First
EF Code First DbContext.SavingChanges
Unfortunately there is no SavingChanges event on the code first DbContext, but there is a way to get to it. The DbContext used for data access with Entity Framework Code First has a simplified API compared to the ObjectContext which is good. Unfortunately it is a bit too simple sometimes. For example there is no… Continue reading EF Code First DbContext.SavingChanges
Separating the Read Model
A typical architecture of a .NET web application is to use EF Code First for data access and MVC to render the web pages. The data model in the database is usually (and should be!) normalized. A normalized data model is also great for updates, but when displaying data it is not enough. E.g. in… Continue reading Separating the Read Model
EF Code First/MVC NotNullAttribute
Unfortunately MVC3 doesn’t respect the [Required] attribute’s AllowEmptyStrings property. When using a class both as an MVC model and as an EF Code First entity this is a problem. What if I want to allow empty strings, but not null values in the database? The problem lies in the client side validation performed by MVC3.… Continue reading EF Code First/MVC NotNullAttribute
EF Code First Navigation Properties and Foreign Keys
An Entity Framework Code First class corresponding to a table with a foreign key typically has two fields for the foreign key. The foreign key as represented in the database and a C# reference. [ForeignKey("BrandId")] public Brand Brand { get; set; } [ForeignKey("Brand")] public int BrandId { get; set; }[ForeignKey("BrandId")] public Brand Brand {… Continue reading EF Code First Navigation Properties and Foreign Keys