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
Category: C#
Send SmtpClient Mails to Disk
When developing a system that sends mails, often the mails shouldn’t be sent for real when testing. Instead they should be made available for investigation. Fortunately, that functionality is built in with the .NET SmtpClient. There is even no need to change the code. It’s just a matter of configuration. Add the following lines to… Continue reading Send SmtpClient Mails to Disk
Dynamic Overload Resolution
Both when coding in C++ and C# I’ve had problems with overload resolution being static. There are workarounds, for example the visitor pattern but it requires quite an effort to implement. More importantly it cannot be implemented without changing the visited element. With C#4’s dynamic keyword there is finally a better solution. To illustrate the problem… Continue reading Dynamic Overload Resolution
Debugging a WCF Service Using a 32 Bit Dll
Recently I was involved in a problem where we had a WCF service referencing a 32 bit dll. The service was set to to “Start WCF Service Host when debugging another project in the same solution”. Unfortunately that ended up with an exception. Could not load file or assembly ‘My32BitLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one… Continue reading Debugging a WCF Service Using a 32 Bit Dll
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