我有一个简单的问题:如何在ConstructUsing中使用Mapper.Map?我正在使用AutoMapper v4.1.1,我有这个代码,我想通过重用代码来清理它.
Mapper.CreateMap<SKU, SKUViewModel>()
.ConstructUsing(m => new SKUViewModel((from texts in m.DescriptionTranslation.TranslationTexts
select new TranslationTuple
{
LanguageId = texts.LanguageId,
LanguageDisplayName = texts.Language.DisplayName,
TranslationText = texts.Text,
NeutralText = texts.NeutralText,
ThreeLetterIsoLanguageName = texts.Language.ThreeLetterISOLanguageName
}).ToList(),
(from texts in m.DisplayNameTranslation.TranslationTexts
select new TranslationTuple
{
LanguageId = texts.LanguageId,
LanguageDisplayName = texts.Language.DisplayName,
TranslationText = texts.Text,
NeutralText = texts.NeutralText,
ThreeLetterIsoLanguageName = texts.Language.ThreeLetterISOLanguageName
}).ToList(),
(from texts in m.PaypalDescriptionTranslation.TranslationTexts
select new TranslationTuple
{
LanguageId = texts.LanguageId,
LanguageDisplayName = texts.Language.DisplayName,
TranslationText = texts.Text,
NeutralText = texts.NeutralText,
ThreeLetterIsoLanguageName = texts.Language.ThreeLetterISOLanguageName
}).ToList()
)); …Run Code Online (Sandbox Code Playgroud) 我正在建立一个多租户网站,我在我的应用程序中使用MapMvcAttributeRoutes和标准MapRoute.当我在不使用RouteAttribute的控制器中时,我也使用此代码成功获取子域名.我无法从使用RouteAttribute的任何控制器/操作中获取子域值.RouteData集合中不存在该值.那么当我在使用RouteAttribute的Action中时如何获取子域值?
这里是RegisterRoutes的代码:
public static void RegisterRoutes(RouteCollection routes)
{
const string mainNamespace = "Presentation.Website.Controllers";
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes(); // Activate attribute Routing
// This will add the parameter "subdomain" to the route parameters
// TODO: Do the same for MapMvcAttribute! but how... ?
routes.Add(new SubdomainConfig(new[] { "www", "yourdomain", "mail" }, new[] { mainNamespace }, CoreSettings.SubDomainKey));
routes.MapRoute(name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { mainNamespace });
}
Run Code Online (Sandbox Code Playgroud)
例如
这将有效:
[AllowAnonymous] …Run Code Online (Sandbox Code Playgroud) 这个问题和这个是一样的。我想从 IActionResult 获取具有相关 html 状态的对象,但 Swagger 向我显示一条“OK”消息而不是相关状态。
我搜索了很多小时才发现配置中的错误,但没有找到任何解决问题的方法。我将向您展示代码:
这是 IActionResult:
[HttpPut("updateuserpricingplan")]
[ProducesResponseType(200)]
[ProducesResponseType(400, Type = typeof(ServiceValidationResult))]
public async Task<IActionResult> UpdateSelection([FromBody]UpdatePricingPlanModel model)
{
var user = await _userService.GetSignedIdUser(this.HttpContext);
var result = await _userService.UpdateUserPricingPlan(user, model.PricingPlanId, _settingService, model.Code);
if (result.Succeeded)
return Ok();
return new ObjectResult(result) { StatusCode = 400 };
}
Run Code Online (Sandbox Code Playgroud)
有趣的是我可以从 Google Chrome 的“网络/响应”选项卡中看到结果和状态代码。
这是我写订阅的方式
this.pricingPlanService.updateSelection(model)
.subscribe(res => {
console.log(res.result);
}, err => { // <== I got "OK" result as string and nothing else
console.log(err.status);
console.log(err.response);
}, () => …Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.net Core 2和EntityFrameWorkCore 2.1.0构建一个新项目,我开始构建数据库结构.现在我必须进行第一次迁移以使我的数据库准备就绪,当我在Package Manager控制台中执行'Add-Migration Init'时,我收到此错误:
The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'. Configure your services to use one that can.
Run Code Online (Sandbox Code Playgroud)
我也尝试了这个文档https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations,我收到的消息是:
Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
Run Code Online (Sandbox Code Playgroud)
我也跟着这篇文章没有任何成功.
如果我尝试没有Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.0.2并使用简单的2表结构,我能够使它工作.
所以现在我需要你的帮助......