Abp: Loading related objects

Created on 30 Nov 2018  Â·  2Comments  Â·  Source: abpframework/abp

How do I properly load my related object? If I my entity is like this
[Required]
[ForeignKey("FK_SectionTypeId")]
public long SectionTypeId { get; set; }
public SectionType SectionType { get; set; }

And my db table has the SectionTypeId, how do I load the section type using the generic repository in abp?

Most helpful comment

On demand

Specify in WithDetails:

```c#
var section = _repository.WithDetails(s => s.SectionType).First(s => s.Id == input.Id);

# By default

Define `DefaultWithDetailsFunc` in ***EntityFrameworkCoreModule.cs**:

```c#
context.Services.AddAbpDbContext<*DbContext>(options =>
{
    options.Entity<Section>(opt =>
    {
        opt.DefaultWithDetailsFunc = q => q.Include(s => s.SectionType);
    });
});

A. No need to specify in WithDetails:

```c#
var section = _repository.WithDetails().First(s => s.Id == input.Id);

B. `Get` includes details by default:

```c#
var section = _repository.Get(input.Id);

Custom repository

ABP Framework's Entity Framework Core Integration Best Practices — Repository Implementation.

All 2 comments

On demand

Specify in WithDetails:

```c#
var section = _repository.WithDetails(s => s.SectionType).First(s => s.Id == input.Id);

# By default

Define `DefaultWithDetailsFunc` in ***EntityFrameworkCoreModule.cs**:

```c#
context.Services.AddAbpDbContext<*DbContext>(options =>
{
    options.Entity<Section>(opt =>
    {
        opt.DefaultWithDetailsFunc = q => q.Include(s => s.SectionType);
    });
});

A. No need to specify in WithDetails:

```c#
var section = _repository.WithDetails().First(s => s.Id == input.Id);

B. `Get` includes details by default:

```c#
var section = _repository.Get(input.Id);

Custom repository

ABP Framework's Entity Framework Core Integration Best Practices — Repository Implementation.

Thanks! That was it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wakuflair picture wakuflair  Â·  3Comments

wocar picture wocar  Â·  3Comments

zsanhong picture zsanhong  Â·  3Comments

hikalkan picture hikalkan  Â·  3Comments

hikalkan picture hikalkan  Â·  3Comments