Beispiel #1
0
        public override Task <RespGetOneUser> GetOneUser(ReqsGetOneUser request, ServerCallContext context)
        {
            Dao.User user = this.Ctx.User.Find(new object[] { request.Condition });

            //1.Auto Mapper,只是RespGetOneUser中含有User这样转换不行
            //Mapper.Initialize(x => x.CreateMap<User, RespGetOneUser>());
            //RespGetOneUser respuser = AutoMapper.Mapper.Map<RespGetOneUser>(user);

            //2.可以的(Initialize是静态方法,只需要执行一次即可)
            //Mapper.Initialize(x => x.CreateMap<gRPCLibServer.User, gRPCLib.User>());
            //gRPCLib.User respuser = AutoMapper.Mapper.Map<gRPCLib.User>(user);

            //3.在启动时,初始化Mapper,以后就可以通过这样的方式转换了,还是比较方便的。
            GrpcServiceApp.User respuser = Mapper.Map <Dao.User, GrpcServiceApp.User>(user);

            return(Task.FromResult(new RespGetOneUser
            {
                User = respuser
            }));
        }
Beispiel #2
0
        public override Task <RespGetOneUser> GetOneUser(ReqsGetOneUser request, ServerCallContext context)
        {
            using (MysqlDbContext ctx = new MysqlDbContext())
            {
                User user = ctx.User.Find(request.Condition);

                //1.Auto Mapper,只是RespGetOneUser中含有User这样转换不行
                //Mapper.Initialize(x => x.CreateMap<User, RespGetOneUser>());
                //RespGetOneUser respuser = AutoMapper.Mapper.Map<RespGetOneUser>(user);

                //2.可以的(Initialize是静态方法,只需要执行一次即可)
                //Mapper.Initialize(x => x.CreateMap<gRPCLibServer.User, gRPCLib.User>());
                //gRPCLib.User respuser = AutoMapper.Mapper.Map<gRPCLib.User>(user);

                //3.在启动时,初始化Mapper,以后就可以通过这样的方式转换了,还是比较方便的。
                gRPCLib.User respuser = Mapper.Map <gRPCLibServer.User, gRPCLib.User>(user);

                return(Task.FromResult(new RespGetOneUser
                {
                    User = respuser
                }));
            }
        }