How to disable changestate tracking for a sub-entity in boilerplate AppService

asp.net-core aspnetboilerplate entity-framework-core

Question

I'm using aspnet core & ef core with boilerplate and would like to disable the changestate tracking for a sub-entity. How do I this this within AppService (ie AsyncCrudAppService).

For example:

Entity:

[Table("tblCategory")]
public class Category : FullAuditedEntity<int>, IMustHaveTenant
{
    public const int MaxCodeLength = 128;
    public const int MaxNameLength = 2048;

    public virtual int TenantId { get; set; }

    [Required]
    [StringLength(MaxCodeLength)]
    public virtual string Code { get; set; }

    [Required]
    [StringLength(MaxNameLength)]
    public virtual string Name { get; set; }

    [ForeignKey("GroupId")]
    public virtual Group Group { get; set; }
    [Required]
    public virtual int GroupId { get; set; }
}

Dto:

[AutoMapFrom(typeof(Category))]
public class CategoryDto : FullAuditedEntityDto<int>
{
    [Required]
    [StringLength(Category.MaxCodeLength)]
    public string Code { get; set; }

    [Required]
    [StringLength(Category.MaxNameLength)]
    public  string Name { get; set; }

    [Required]
    public  int GroupId { get;  set; }

    [DisableValidation]
    public GroupDto Group{ get;  set; }

}

AppService Update Method:

public override async Task<CategoryDto> Update(CategoryDto input)
{
    var cat = await _categoryManager.GetA(input.Id);

    MapToEntity(input, cat);

    //I'd like to disable the tracking of cat.Group here ?

    await _categoryManager.UpdateA(cat);

    return await Get(input);
}

I'd like to disable the change detection for cat.Group, how do I do this ?

Thanks in advance.

1
0
8/12/2018 8:06:57 AM

Accepted Answer

Using AsNoTracking when loading resolves the issue

0
8/15/2018 11:37:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow