jeudi 25 août 2016

How to find specific entity in a table with auto increment key? (Entity framework)

I have following test method:

  [Test]
        public void GetUserTest()
        {
            //Arrange
            User user = new User();
            user.Name = "someName";
            user.BirthDate = DateTime.Now;
            _dataContext.Users.Add(user);
            _dataContext.SaveChanges();

            //Execute

            user = _dbService.GetUser(???);

            //Assert

            Assert.NotNull(user);
        }

ID is auto generated for User object, so how should I get this particular one? Behind GetUser() im using a Find(id) method from DbSet class.

Aucun commentaire:

Enregistrer un commentaire