C#: отображение объекта из другого объекта - PullRequest
0 голосов
/ 23 апреля 2020

Я хотел бы создать экземпляр с некоторым атрибутом с сущностями.

См. Здесь:

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

Спасибо за помощь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...