The binary operator Equal is not defined between type Nullable and Int32

asp.net-mvc-4 entity-framework model

Accepted Answer

Try using the Fluent API to explicitly set the field to Optional:

 public class YourContext : DbContext
    {
        public DbSet<DeviceConfigurationModel> DeviceConfigurations { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<DeviceConfigurationModel>().Property(x => x.PORT).IsOptional();
        }
    }

This should make the type nullable by default.

Apparently, designating your property asint? in place ofNullable<int> will result in EF producing your property in the expected manner as well.

2
6/5/2013 2:03:30 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow