Skip to content

Option to not load the navigation property #45

Description

@leopripos

Do we already have this feature?

If no, I think this is necessery to make sure that Include statement is called or not in my repository or query.
The sample scenario:

public class Lesson {
  public int Id {get; set;}
}

public class Student {
  public int Id {get; set;}

  public List<Lesson> Lessons   { get; set; }
}

var student1 = new Student(){
  Id = 1,
  Lessons = new List<Lesson>(){
    new Lesson(){
      Id = 1,
    }
  }
}

var students = new List<Student>(){
  student1
};

var dataSetMock = students.AsQueryable().BuildMockDbSet();

var dbContextMock = new Mock<IDbContextInterface>();
dbContextMock.SetupGet(e => e.Students)
    .Returns(dataSetMock.Object);

var repository = new StudentsRepository(dbContextMock.Object);

var studentResult = repository.GetById("12312312");

studentResult.Lessons.Should().NotBeNull();

But this will causes studentResult == student1 returns false because we need to instansiate new object.

My suggestion for this, we can add new param in BuildMockDbSet

public static IQueryable<TEntity> BuildMock<TEntity>(this IQueryable<TEntity> data, bool loadNavigation= true) where TEntity : class {}

Thanks
:)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions