EF 코어 1.0.1 및 메모리의 SQL 라이트와 함께 automapper 5.2.0 사용. 내가 대신 내가 얻을이 예상되는 데이터베이스 쿼리를 만들 얻을 수없는이 :QueryableExtensions Project 투영되지 않는지도
Microsoft.EntityFrameworkCore.Query.RelationalQueryCompilationContextFactory : 경고 : (가) 탐색 작업을 포함합니다 : 'a.PostTags.Tag'무시 최종 검색어에서 대상 탐색에 도달 할 수 없기 때문에 결과. 이 경고를 구성하려면 DbContextOptionsBuilder.ConfigureWarnings API (이벤트 ID 'CoreEventId.IncludeIgnoredWarning')를 사용하십시오. DbContext.OnConfiguring 메서드를 재정의하거나 응용 프로그램 서비스 공급자에서 AddDbContext를 사용하는 경우 ConfigureWarnings을 사용할 수 있습니다. Microsoft.EntityFrameworkCore.Query.RelationalQueryCompilationContextFactory : 경고 : 쿼리 결과에서 대상 탐색에 도달 할 수 없으므로 탐색에 대한 포함 작업 : 'a.Responses.CreatedByUser'가 무시되었습니다 ( ). 이 경고를 구성하려면 DbContextOptionsBuilder.ConfigureWarnings API (이벤트 ID 'CoreEventId.IncludeIgnoredWarning')를 사용하십시오. DbContext.OnConfiguring 메서드를 재정의하거나 응용 프로그램 서비스 공급자에서 AddDbContext를 사용하는 경우 ConfigureWarnings을 사용할 수 있습니다. Microsoft.EntityFrameworkCore.Query.RelationalQueryCompilationContextFactory : 경고 : 최종 쿼리에서 대상 탐색에 연결할 수 없기 때문에 탐색에 대한 포함 작업 : 'a.CreatedByUser'가 무시되었습니다. 결과는 결과입니다. 이 경고를 구성하려면 DbContextOptionsBuilder.ConfigureWarnings API (이벤트 ID 'CoreEventId.IncludeIgnoredWarning')를 사용하십시오. DbContext.OnConfiguring 메서드를 재정의하거나 응용 프로그램 서비스 공급자에서 AddDbContext를 사용하는 경우 ConfigureWarnings을 사용할 수 있습니다. Microsoft.EntityFrameworkCore.Query.RelationalQueryCompilationContextFactory : 경고 : 최종 쿼리 결과에서 대상 탐색에 도달 할 수 없기 때문에 탐색에 대한 포함 작업 : 'a.Category'가 무시되었습니다. 에이 경고를 구성하려면 DbContextOptionsBuilder.ConfigureWarnings API (이벤트 ID 'CoreEventId.IncludeIgnoredWarning')를 사용하십시오. DbContext.OnConfiguring 메서드를 재정의하거나 응용 프로그램 서비스 공급자에서 AddDbContext를 사용하는 경우 ConfigureWarnings을 사용할 수 있습니다. Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory : 정보 : 실행 된 DbCommand (0ms) [매개 변수 = [@__ id_0 = '?]], CommandType ='텍스트 ', CommandTimeout = '30'] SELECT 1 FROM " a " "a "."PostId"= @__ ID_0 LIMIT 여기
이 내 설정이다 :
시작 :
public class Startup
{
private MapperConfiguration _mapperConfiguration { get; set; }
public Startup(IHostingEnvironment env)
{
...
_mapperConfiguration = new MapperConfiguration(cfg =>
{
...
cfg.AddProfile(new PostMapperProfile());
});
_mapperConfiguration.AssertConfigurationIsValid();
}
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSingleton<IMapper>(sp => _mapperConfiguration.CreateMapper());
services.AddSingleton<MapperConfiguration>(sp => _mapperConfiguration);
}
}
PostMapperProfile :
public class PostMapperProfile : Profile
{
public PostMapperProfile()
{
var postDetailMap = CreateMap<PostEntity, PostDetailModel>();
postDetailMap.ForAllMembers(opt => opt.Ignore());
postDetailMap.ForMember(m => m.Category, opt => opt.MapFrom(src => src.CategoryId.HasValue ? src.Category : null));
postDetailMap.ForMember(m => m.CreatedAt, opt => opt.MapFrom(src => src.CreatedAt));
postDetailMap.ForMember(m => m.CreatedByUser, opt => opt.MapFrom(src => src.CreatedByUser));
postDetailMap.ForMember(m => m.PostId, opt => opt.MapFrom(src => src.PostId));
postDetailMap.ForMember(m => m.PostState, opt => opt.MapFrom(src => src.PostState));
postDetailMap.ForMember(m => m.PostType, opt => opt.MapFrom(src => src.PostType));
postDetailMap.ForMember(m => m.ResponsesCount, opt => opt.MapFrom(src => src.Responses.Count));
postDetailMap.ForMember(m => m.Text, opt => opt.MapFrom(src => src.Text));
postDetailMap.ForMember(m => m.Tags, opt => opt.MapFrom(src => src.PostTags.Select(x => x.Tag).ToList()));
postDetailMap.ForMember(m => m.Title, opt => opt.MapFrom(src => src.Title));
postDetailMap.ForMember(m => m.ViewsCount, opt => opt.MapFrom(src => src.ViewsCount));
postDetailMap.ForMember(m => m.VotesCount, opt => opt.MapFrom(src => src.VotesCount));
postDetailMap.ForMember(m => m.Responses, opt => opt.MapFrom(src => PagedList<ResponseEntity>.Create(src.Responses.Take(10).Select(x => AutoMapper.Mapper.Map<ResponseDetailModel>(x)).ToList(), 1, 10, src.Responses.Count)));
}
}
BlogpostService :
public class BlogpostService
{
private readonly AppDbContext m_context;
private readonly IMapper m_mapper;
private readonly MapperConfiguration m_config;
public BlogpostService(AppDbContext context, IMapper mapper, MapperConfiguration config)
{
m_context = context;
m_mapper = mapper;
m_config = config;
}
public PostDetailModel GetPostDetail(int id)
{
var s = m_context.Posts
.Include(a => a.CreatedByUser)
.Include(a => a.Category)
.Include(a => a.PostTags)
.ThenInclude(a => a.Tag)
.Include(a => a.Responses)
.ThenInclude(b => b.CreatedByUser)
.Where(x => x.PostId == id);
var d = s.Single();
return s.ProjectTo<PostDetailModel>(m_config).Single();
}
}
,
테스트 :
public class PostRepositoryTests
{
public TestServer server { get; }
public HttpClient client { get; }
private readonly AppDbContext Context;
private readonly UserManager<UserEntity> UserManager;
private readonly IMapper Mapper;
private readonly MapperConfiguration Config;
public PostRepositoryTests()
{
...
Context = serviceProvider.GetRequiredService<AppDbContext>();
UserManager = serviceProvider.GetRequiredService<UserManager<UserEntity>>();
Mapper = serviceProvider.GetService<IMapper>();
Config = serviceProvider.GetService<MapperConfiguration>();
}
[Fact]
public void CreatePost()
{
var user = new UserEntity();
user.Email = "[email protected]";
var ct = UserManager.CreateAsync(user, "Testing123..");
var service = new BlogpostService(Context, Mapper, Config);
var blogpost = new CreateBlogpostRequest();
blogpost.Title = "Some title";
blogpost.Content = "Some content";
blogpost.Tags = new List<TagDTO>(){
new TagDTO{
Label = "Tag1",
},
new TagDTO{
Label = "Tag2",
},
new TagDTO{
Label = "Tag3",
}
};
var response = service.CreateBlogpost(blogpost, user.Id);
var postDetail = service.GetPostDetail(response.PostId);
Assert.Equal(postDetail.Tags.Count, 3);
}
}
어떻게됩니까? –
@IvanStoev 해당 줄을 제거했지만 결과는 여전히 동일합니다. – formatc
너무 나쁨. 완전한'mcve' (repro) 코드 또는 링크를 게시 할 수 있습니까? 기본적으로'PostEntity'와'PostDetailModel' 클래스가 없으면 우리가 할 수있는 일이 없습니다. –