C# 首先将片段错误TimeZoneInfo对象映射到db EF代码

C# 首先将片段错误TimeZoneInfo对象映射到db EF代码,c#,wpf,entity-framework,telerik,dbcontext,C#,Wpf,Entity Framework,Telerik,Dbcontext,我在RadScheduleView中使用Teleriks WPF UI,在将自定义约会类映射到数据库时遇到问题。我使用的是代码优先的方法,当我创建自定义资源时,一切正常,但自定义约会类失败 我在编译时得到这个内部错误 "\r\n(6,10) : error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties Bokning.TimeZone in Set Bokning

我在RadScheduleView中使用Teleriks WPF UI,在将自定义约会类映射到数据库时遇到问题。我使用的是代码优先的方法,当我创建自定义资源时,一切正常,但自定义约会类失败

我在编译时得到这个内部错误

"\r\n(6,10) : error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties Bokning.TimeZone in Set Bokning.\r\nAn Entity with Key (PK) will not round-trip when:\r\n  Entity is type [TelerikWpfApp1.Bokning]\r\n"
这是我的篮球课

class Bokning : Appointment
{
    public Bokning() { }
    private int id;
    public int Id
    {
        get
        {
            return this.Storage<Bokning>().id;
        }

        set
        {
            var storage = this.Storage<Bokning>();
            if (storage.id != value)
            {
                storage.id = value;
                this.OnPropertyChanged(() => this.Id);
            }
        }
    }
    public override IAppointment Copy()
    {
        var customAppointment = new Bokning();
        customAppointment.CopyFrom(this);
        return customAppointment;
    }
    public override void CopyFrom(IAppointment other)
    {
        var customAppointment = other as Bokning;
        if (customAppointment != null)
        {
            this.Id = customAppointment.Id;
        }
        base.CopyFrom(other);
    }

}
class Bokning:预约
{
公共Bokning(){}
私有int-id;
公共整数Id
{
得到
{
返回此.Storage().id;
}
设置
{
var storage=this.storage();
if(storage.id!=值)
{
storage.id=值;
this.OnPropertyChanged(()=>this.Id);
}
}
}
公共覆盖IAppointment副本()
{
var customAppointment=new Bokning();
customAppointment.CopyFrom(此);
返回客户预约;
}
公共覆盖无效复制自(IAppoition other)
{
var customAppointment=其他如Bokning;
if(customAppointment!=null)
{
this.Id=customAppointment.Id;
}
base.CopyFrom(其他);
}
}
这就是我的背景

class DBContext : DbContext
{
    public DBContext(): base("ADO Solutions")
    {
    }
    public DbSet<Personal> Personal { get; set; }

    public DbSet<Jobb> Jobb { get; set; }

    public DbSet<Bokning> Bokning { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }


}
classdbcontext:DBContext
{
public DBContext():base(“ADO解决方案”)
{
}
公共数据库集个人{get;set;}
公共DbSet Jobb{get;set;}
公共数据库集Bokning{get;set;}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove();
}
}
个人和工作班的工作没有问题。但是博克宁班给我带来了麻烦。我认为从Appointment类映射TimeZone属性时出现问题。在数据库中创建Bokning表,但并非所有列都存在。我认为它崩溃是因为TimeZone属性是TimeZoneInfo对象

我想我需要一种在db中将TimeZoneInfo对象映射为字符串的方法,但我甚至不确定这是否是问题所在

编辑:我可能使用单词map和mapping错误

添加

modelBuilder.Entity<Bokning>().Ignore(t => t.TimeZone);
modelBuilder.Entity().Ignore(t=>t.TimeZone);
创建一个模型


使其忽略时区属性,这很好。它现在可以工作了

只需在数据库中保存
TimeZoneInfo.Id
属性即可。然后使用
TimeZoneInfo.FindSystemTimeZoneById()
方法获取
TimeZoneInfo

但这样会丢失时区,因为这不会将时区属性/属性添加到db表中。到目前为止,我还没有找到更好的解决方案,然后将时区存储为字符串。