小编Sam*_*tar的帖子

我可以将foreach和LINQ查询合并为一个吗?

我有一个C#代码,如下所示:

foreach (var entry in this.ChangeTracker.Entries()
                     .Where(e => e.Entity is IAuditableTable &&
                                 e.State == EntityState.Added))
{
    IAuditableTable e = (IAuditableTable)entry.Entity;
    e.ModifiedDate = DateTime.Now;
}
Run Code Online (Sandbox Code Playgroud)

这似乎就像foreach和LINQ的结合.sometone告诉我,我可以删除foreach并将其合并到一个LINQ语句中

c# linq

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

git命令中的<pathspec>是什么?

我已经在我的应用程序中更新,修改和删除了文件,现在我已准备好提交.这是状态:

C:\G\ab\WebAdminApp>git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   WebAdminApp.csproj
        modified:   WebAdminApp.csproj.user
        modified:   app/admin/controllers/ContentController.ts
        deleted:    app/admin/interfaces/IEnumService.ts
        modified:   app/admin/interfaces/IHomeController.d.ts
        modified:   lib/pagedown/Markdown.Sanitizer.ts
        deleted:    lib/typings/global.ts
        modified:   package.json
        modified:   ../abilitest-admin.v12.suo

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        app/interfaces/IEnumService.d.ts
        app/interfaces/IUtilityService.d.ts
        ../npm-debug.log
Run Code Online (Sandbox Code Playgroud)

没有更改添加到提交(使用"git add"和/或"git commit -a")

当我进入:

git add . …
Run Code Online (Sandbox Code Playgroud)

git github

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

如何正确刷新在VS 2015 Web开发环境中运行的AngularJS SPA

我有一个AngularJS SPA应用程序,我使用Visual Studio 2015开发.当我点击发布它发布index.html并且工作得很好.但是,如果我在页面上并单击刷新,则会尝试刷新SPA页面,例如example.com/home/about.这失败了,因为我没有家/关于页面.

有没有办法可以修改我的web.config文件(仅用于本地测试),这样它实际上会转到index.html(加载它)然后转到/ home/about状态?

这是我当前的web.config:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

visual-studio angularjs

8
推荐指数
1
解决办法
277
查看次数

LINQ如何订购集合

我有一个类对象的集合:

Tests
Run Code Online (Sandbox Code Playgroud)

此集合包含许多Test实例:

public class Test {
   public string column1 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想使用LINQ来命令内容Tests并将其放入一个名为的新集合中TestsOrdered.我想按内容订购column1.我想用LINQ做这个,后来我想在订购中添加更多内容.

我怎么能用LINQ做到这一点.

c# linq

7
推荐指数
1
解决办法
4111
查看次数

如何用where指定泛型?

我试图指定这个通用但我收到多个错误:

    public void AddOrUpdate(T item, V repo) where T: IAuditableTable, V: IAzureTable<TableServiceEntity>
    {
        try
        {
            V.AddOrUpdate(item);
        }
        catch (Exception ex)
        {
            _ex.Errors.Add("", "Error when adding account");
            throw _ex;
        }
    }
Run Code Online (Sandbox Code Playgroud)

例如,在第一行的V之后的":"给出错误:

Error   3   ; expected
Run Code Online (Sandbox Code Playgroud)

加上其他错误:

Error   2   Constraints are not allowed on non-generic declarations 
Error   6   Invalid token ')' in class, struct, or interface member declaration 
Error   5   Invalid token '(' in class, struct, or interface member declaration 
Error   7   A namespace cannot directly contain members such as fields …
Run Code Online (Sandbox Code Playgroud)

c#

7
推荐指数
2
解决办法
2186
查看次数

当我尝试将枚举格式化为字符串时,为什么我的格式会给我一个错误?

我有以下枚举:

public enum EReferenceKey {
        Accounts             = 1,
        Emails                = 3,
        Phones               = 4
}
Run Code Online (Sandbox Code Playgroud)

当我的枚举变量pk是Accounts时,我尝试将其转换为"01"

var a = pk.ToString("00");
Run Code Online (Sandbox Code Playgroud)

它给了我以下例外:

格式字符串只能是"G","g","X","x","F","f","D"或"d"

谁能解释我做错了什么?

c#

7
推荐指数
1
解决办法
4089
查看次数

a == null和=== null之间有什么区别?

有人可以通过解释差异来帮助我.根据我的理解,===确实匹配,但与null相比,这意味着什么?

javascript

7
推荐指数
1
解决办法
3775
查看次数

升级到1.3后,控制器未在Typescript应用程序中定义

我的应用程序中有以下代码:

angular.module('home', [])
    .controller('homeHomeController', HomeHomeController)
    .controller('homeContentController', HomeContentController);
Run Code Online (Sandbox Code Playgroud)

class HomeHomeController {
    static $inject = [
        '$http',
        'examService',
        'stateService',
        'userService'
    ];
    constructor(
        private $http: ng.IHttpService,
        private $es: IExamService,
        private $ss: IStateService,
        private $us: IUserService
        ) {
        var self = this;   
    }
} 
Run Code Online (Sandbox Code Playgroud)

我刚刚升级到AngularJS 1.3,现在我收到此错误:

Error: [ng:areq] Argument 'HomeHomeController' is not a function, got undefined
http://errors.angularjs.org/1.3.0/ng/areq?p0=HomeHomeController&p1=not%20aNaNunction%2C%20got%20undefined
    at http://127.0.0.1:17315/Scripts/angular.js:80:12
    at assertArg (http://127.0.0.1:17315/Scripts/angular.js:1610:11)
    at assertArgFn (http://127.0.0.1:17315/Scripts/angular.js:1620:3)
    at http://127.0.0.1:17315/Scripts/angular.js:8319:9
    at http://127.0.0.1:17315/Scripts/angular.js:7496:34
    at forEach (http://127.0.0.1:17315/Scripts/angular.js:343:20)
    at nodeLinkFn (http://127.0.0.1:17315/Scripts/angular.js:7483:11)
    at compositeLinkFn (http://127.0.0.1:17315/Scripts/angular.js:6991:13)
    at publicLinkFn (http://127.0.0.1:17315/Scripts/angular.js:6870:30)
    at compile …
Run Code Online (Sandbox Code Playgroud)

angularjs typescript

7
推荐指数
1
解决办法
1673
查看次数

1.3.0 rc0之后<select>的ngChange问​​题

我一直在使用1.3的beta版本,现在转移到1.3.1后,我注意到一个问题,通过检查所有早期版本,我看到它似乎已经在1.3.0 rc1中启动了.

我有这样的代码:

<select ng-model="home.modal.topicId"
        ng-change="ctrl.modalTopicChanged()"
        ng-options="item.id as item.name for item in home.modal.option.topics.data"
        ng-required="true">
        <option style="display: none;" value="">Select Topic</option>
</select>
Run Code Online (Sandbox Code Playgroud)

在rc1之前,首次显示表单时未触发 ng-change .现在它被一个未定义的home.modal.topicId解雇了.这对我来说是一个突破性的变化,但在破坏性变化部分没有提到它,我想知道它是否是一个尚未被注意到的错误.

这是生成的堆栈跟踪:

TypeError: Cannot read property 'dataMap' of undefined
    at AdminProblemController.modalTopicChanged (http://127.0.0.1:17315/Content/app/admin/controllers/ProblemController.js:109:114)
    at $parseFunctionCall (http://127.0.0.1:17315/Scripts/angular.js:11387:18)
    at Scope.$get.Scope.$eval (http://127.0.0.1:17315/Scripts/angular.js:13276:28)
    at http://127.0.0.1:17315/Scripts/angular.js:19888:13
    at http://127.0.0.1:17315/Scripts/angular.js:19499:9
    at forEach (http://127.0.0.1:17315/Scripts/angular.js:331:20)
    at $$writeModelToScope (http://127.0.0.1:17315/Scripts/angular.js:19497:5)
    at writeToModelIfNeeded (http://127.0.0.1:17315/Scripts/angular.js:19490:14)
    at http://127.0.0.1:17315/Scripts/angular.js:19484:9
    at validationDone (http://127.0.0.1:17315/Scripts/angular.js:19420:9) 
Run Code Online (Sandbox Code Playgroud)

我在这里注意到的是一个新函数:writeToModelIfNeeded

当我查看更改日志差异时,在检查所有更改和行号时,我找不到提及此功能的任何内容.

我想就此提出一些建议.首先是可以找到导致添加writeToModelIfNeeded的更改,其次是选择框的正确功能.我认为整个想法是只有在定义模型值时才会触发ng-change.

这里参考的是新代码的区域,似乎已经添加了1.3.0 rc.1

**
   * @ngdoc method
   * @name ngModel.NgModelController#$commitViewValue
   *
   * @description …
Run Code Online (Sandbox Code Playgroud)

angularjs

7
推荐指数
1
解决办法
2016
查看次数

如何使用$ q.all的AngularJS哈希选项?

我环顾四周,一无所获地解释如何使用它.文件说明:

返回将使用值的数组/散列解析的单个promise,每个值对应于promises数组/散列中相同索引/键的promise.如果任何承诺通过拒绝得到解决,则此结果承诺将被拒绝并具有相同的拒绝值.

但没有例子.

有没有人有任何使用密钥/哈希方法的例子?

angularjs

7
推荐指数
1
解决办法
1100
查看次数

标签 统计

angularjs ×4

c# ×4

linq ×2

git ×1

github ×1

javascript ×1

typescript ×1

visual-studio ×1