示例#1
0
        //public override Hero AnonymousTypeToT(object anonymous)
        //{
        //    var hero = new BaseObjectService().AnonymousTypeToT(anonymous) as Hero;

        //    hero = AnonymousTypeToT(hero);

        //    return hero;
        //}

        public override void ConvertToPersistent(Hero disconnectedEntity, Hero persistent = null, Func <Hero> populatePersistent = null)
        {
            populatePersistent = () =>
            {
                using (var uow = new Dota2UnitofWork())
                {
                    var repository = new HeroRepository(uow.Context);

                    new HeroService().Select();

                    //return repository.Select(repository.UniqueFilter(disconnectedEntity)).ToList()
                    //.Select(s=> s as Hero)
                    //.SingleOrDefault();

                    return(repository.Select(repository.UniqueFilter(disconnectedEntity), repository.GetAllIncludes())
                           .Select(q => new
                    {
                        q.Id,
                        q.Name,
                        q.ImageId
                    })
                           .ToList()
                           .Select(h => new Hero()
                    {
                        Id = h.Id,
                        Name = h.Name,
                        ImageId = h.ImageId
                    })
                           .SingleOrDefault());
                }
            };

            persistent = persistent ?? populatePersistent();

            base.ConvertToPersistent(disconnectedEntity, persistent, populatePersistent);

            new CharacterService().ConvertToPersistent(disconnectedEntity, persistent, populatePersistent);
        }