C#:从另一个实体映射实体

我想创建一个带有实体属性的实例。

查看此处:

public class Feature : ICharacteristic<Feature>
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public int Id { get; set; }
    public string Name { get; set; 
}

public class AttributeFeature : IAttribute<AttributeFeature>
{
    [Key,Column(Order = 0)]
    public int IdCharactere { get; set; }
    [Key,Column(Order = 1)]
    public int Id { get; set; }

    public int Value { get; set; }

    public virtual Character Character { get; set; }
    public virtual Feature Feature { get; set; }
}

private void Mapper<TEntity>(TEntity entity,int value) where TEntity : class,ICharacteristic<TEntity>
{
    object destination;

    if (entity is Feature)
    {
        destination = ToDestination<AttributeFeature>(value);
        DbAttributeRepository<AttributeFeature> repository = new DbAttributeRepository<AttributeFeature>(destination as AttributeFeature,_idCharacter);
        repository.Create(destination as AttributeFeature);
    }
}

private TEntity ToDestination<TEntity>(int value) where TEntity : class,IAttribute<TEntity>
{
    var entity = activator.CreateInstance<TEntity>();

    entity.Id = this.Id;    // This id comes from Featuren,Skill ...
    entity.IdCharactere = _idCharacter;
    entity.Value = value;    

    return entity;
}

我有几个实体,我想找到一种解决方案来关联实体,例如

Feature -> AttributeFeature
Skill -> AttributeSkill

感谢您的帮助。

yinghuochong512 回答:C#:从另一个实体映射实体

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2373454.html

大家都在问