Sto cercando di creare un codice di prima classe con i miei tipi di oggetti e ottenere questo errore:deve essere non annullabile al fine di utilizzare come parametro di 'T'
.MTObject'
must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration<TStructuralType>.Property<T>(System.Linq.Expressions.Expression<System.Func<TStructuralType,T>>)
'
C'è un modo per dichiarare il mio proprietà di classe per superare questo errore?
codice è qui sotto:
// Simple Example
public class MTObject
{
public string Object { get; set; }
public MTObject()
{
}
}
public class Person
{
public decimal Id { get; set; }
//public string Name { get; set; }
public MTObject Name { get; set; }
public Int32 Age { get; set; }
}
public class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration() : base()
{
HasKey(p => p.Id);
Property(p => p.Id).HasColumnName("ID").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(p => p.Name).HasColumnName("NAME").IsOptional();
Property(p => p.Age).HasColumnName("AGE").IsOptional();
ToTable("Person");
}
}
public class PersonDataBase : DbContext
{
public DbSet<Person> Persons { get; set; }
public PersonDataBase(string connectionString) : base(connectionString)
{
Database.CreateIfNotExists();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new PersonConfiguration());
base.OnModelCreating(modelBuilder);
}
}
// End Simple EXample
È questo .net? Qualunque cosa, si prega di taggare la domanda con il tag della lingua (e magari rimuovere uno dei tag meno rilevanti come "errori del compilatore") – Bohemian