小编DJB*_*DJB的帖子

使用AutoMapper将DataTable映射到对象(DTO)

我正在尝试使用AutoMappers DynamicMap功能将DataTable映射到对象(DTO).

DataTable dt;
dt = new dalAllInvestors().InvestorNameSearch(investorNameSearch);

// Look at DynamicMap - Urgent 
List<dtoAPISimpleInvestor> apiObject = AutoMapper.Mapper.DynamicMap<IDataReader, List<dtoAPISimpleInvestor>>(
dt.CreateDataReader());

return apiObject;


public class dtoAPISimpleInvestor
{
    public int FirmID { get; set; }
    public string FirmName { get; set; }
    public string Type { get; set; }
    public string Location { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

dt返回10行但是当你看到apiObject时它没有返回任何行,这似乎没有任何意义.我现在已经看了一段时间,谷歌搜索后看起来我正在做的正确.

正确的列在dt中返回时映射到 dtoAPISimpleInvestor

有人能帮帮我吗?

c# automapper

10
推荐指数
2
解决办法
1万
查看次数

凭据标志为"true",但是"Access-Control-Allow-Credentials"

我正在尝试从AngularJS页面连接到ASP.NET Web-API Web服务,我得到以下内容

凭据标志为"true",但"Access-Control-Allow-Credentials"标头为"".允许凭据必须为"true".原产地" 的http://本地主机:221 "因此不允许访问.

       var cors = new EnableCorsAttribute("http://localhost:221", "*","GET,PUT,POST,DELETE");
       config.EnableCors(cors);
Run Code Online (Sandbox Code Playgroud)

使用此AngularJS

        $http({
        method: 'GET',
        url: 'http://localhost:1980/api/investors/62632',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        withCredentials: true
        //    withCredentials: true,
    }).then(function onUserComplete(response) {
        // this callback will be called asynchronously
        // when the response is available
    }, function onError(response) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
Run Code Online (Sandbox Code Playgroud)

阅读了很多文章后,我将其添加到web.config中

   <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="http://localhost:221" />
  </customHeaders>
</httpProtocol>
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息

'Access-Control-Allow-Origin'标头包含多个值localhost:221,localhost:221,但只允许一个.原因localhost:221因此不允许访问.

这真的没有任何意义,因为我已经添加了一次,它没有找到它,但我将它添加到web.config并得到一个错误说它被添加了多次.我看了很多文章,似乎找不到合适的答案.我正在使用Google Chrome.非常感谢你的帮助,因为我现在正在拔头发.

c# asp.net asp.net-web-api angularjs

8
推荐指数
3
解决办法
2万
查看次数

标签 统计

c# ×2

angularjs ×1

asp.net ×1

asp.net-web-api ×1

automapper ×1