我试图将类中的某些属性与数据库中的模型进行映射,但是某些属性未映射,我不知道为什么。
结果是:
{“ cessionID”:5,“ contractID”:14,“ cessionTypeID”:1,“ cessionStatusID”:1,“ cessionDate”:“ 2018-06-25T00:00:00”,“ cessionTime”:“ 00 :00:00“,” documentPath“:”文档“,” assignmentCost“:1000.0000,” note“:” note“,” tswUserID“:2486,” lastUpdate“:null}
如您所见,属性lastUpdate和属性cessionTime没有映射。
这是我的dbContext
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{
}
public DbSet<Cessions>Cessions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("Relational:DefaultSchema", "VIDAMX\\davidmata");
modelBuilder.Entity<Cessions>(entity =>
{
entity.HasKey(e => e.CessionID);
entity.ToTable("Cessions", "dbo");
entity.Property(e => e.CessionID).HasColumnName("CessionID");
entity.Property(e => e.AssignmentCost)
.HasColumnType("money")
.HasDefaultValueSql("((0))");
entity.Property(e => e.CessionDate)
.HasColumnType("date")
.HasDefaultValueSql("(getdate())");
entity.Property(e => e.CessionStatusID).HasColumnName("CessionStatusID");
entity.Property(e => e.CessionTime).HasDefaultValueSql("(getdate())").HasColumnName("CessionTime");
entity.Property(e => e.CessionTypeID).HasColumnName("CessionTypeID");
entity.Property(e => e.ContractID).HasColumnName("ContractID");
entity.Property(e => e.DocumentPath)
.IsRequired()
.HasMaxLength(300)
.IsUnicode(false)
.HasDefaultValueSql("('')");
entity.Property(e => e.LastUpdate)
.IsRequired()
.IsRowVersion();
entity.Property(e => e.Note)
.IsRequired()
.HasMaxLength(2000)
.IsUnicode(false)
.HasDefaultValueSql("('')");
entity.Property(e => e.TSWUserID).HasColumnName("TSWUserID");
entity.HasOne(d => d.CessionStatus)
.WithMany(p => p.Cessions)
.HasForeignKey(d => d.CessionStatusID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK__Sessions__Sessio__398D8EEE");
entity.HasOne(d => d.CessionTypes)
.WithMany(p => p.Cessions)
.HasForeignKey(d => d.CessionTypeID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK__Sessions__Sessio__38996AB5");
});
}
}
这是我的Cession课程
public partial class Cessions
{
public Cessions()
{
Assignments = new HashSet<Assignments>();
CessionDocuments = new HashSet<CessionDocuments>();
}
public int CessionID { get; set; }
public int ContractID { get; set; }
public int CessionTypeID { get; set; }
public int CessionStatusID { get; set; }
public DateTime CessionDate { get; set; }
public TimeSpan CessionTime { get; set; }
public string DocumentPath { get; set; }
public decimal AssignmentCost { get; set; } //The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.
public string Note { get; set; }
public int TSWUserID { get; set; }
public byte[] LastUpdate { get; set; }
public virtual CessionStatus CessionStatus { get; set; }
public virtual CessionTypes CessionTypes { get; set; }
public virtual ICollection<Assignments> Assignments { get; set; }
public virtual ICollection<CessionDocuments> CessionDocuments { get; set; }
}
数据库中的表: