コード例 #1
0
        public async Task <Student> GetStudentAsync(string email)
        {
            Guard.NotNullOrEmpty(email, nameof(email));

            var filter = Builders <BsonDocument> .Filter
                         .Eq(Fields.StudentEmail, email);

            var document = await _context.Students
                           .Find(filter)
                           .SingleOrDefaultAsync();

            if (document == null)
            {
                return(null);
            }

            return(new Student(
                       id:         FromBson.GetId(document),
                       version:    FromBson.GetVersion(document),
                       email:      FromBson.GetStudentEmail(document),
                       name:       FromBson.GetStudentName(document),
                       age:        FromBson.GetStudentAge(document)
                       ));
        }