小编Max*_*ler的帖子

如何在Entity Framework 6.1 Code First模型中更改聚簇索引并将其应用于Azure数据库

使用Entity Framework 6.1代码优先模型,将表上的聚簇索引从默认ID更改为另一组列的最佳方法是什么.Azure不允许没有聚簇索引的表.

  public partial class UserProfile 
  {
    public override Guid ID { get; set; }

    [Index( "CI_UserProfiles_UserID", IsClustered = true)]
    public Guid UserID { get; set; }

    [Required]
    public Guid FieldID { get; set; }

    [Required]
    [StringLength(400)]
    public string Value { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

在表上UserProfiles,ID已经是主键和聚簇索引.添加

[Index( "CI_UserProfiles_UserID", IsClustered = true)] 
Run Code Online (Sandbox Code Playgroud)

到UserID创建此迁移:

CreateIndex("dbo.UserProfiles", "UserID", clustered: true, name: "IX_UserProfiles_UserID");
Run Code Online (Sandbox Code Playgroud)

执行迁移会生成以下错误:

无法在表'dbo.UserProfiles'上创建多个聚簇索引.删除现有的聚簇索引"PK_dbo.UserProfiles",然后再创建另一个.

entity-framework azure

6
推荐指数
2
解决办法
2296
查看次数

使用 GitHub V3 API (REST) 创建分支

我正在尝试通过 REST 使用 GitHub V3 API 分叉一个存储库,但是,我在按照文档发出 POST 请求时遇到问题(https://developer.github.com/v3/repos/forks/#create-一把叉子)。

基本上,到目前为止我所拥有的:

  • 具有 OAuth 令牌的登录用户
  • 对 API (URL:) 的 POST 请求设置https://api.github.com/repos/carmichaelalonso/infiniteflight/forks/- 我首先使用 hurl.it 对此进行测试。
  • 请求中的标头:一个标头的名称Authorization值为“token ...”,另一个标头的Content-Type值指定application/json
  • 具有以下 JSON 的正文:{"organization" : "shortlisthome"}(shortlisthome 是我尝试将存储库分叉到的帐户。

我不打算将其分叉给一个组织,而不是一个标准用户帐户,这就是我感到困惑的地方。当我运行请求时,我没有收到任何身份验证错误或 404 错误(我以前有过,但我错误地输入了不正确的值,导致了此类错误)。

当我运行此请求时,我得到以下结果(422 无法处理的请求):

{
    "message": "Validation Failed",
    "documentation_url": "---url-to-docs---",
    "errors": [
        {
            "resource": "Fork",
            "code": "invalid",
            "field": "organization"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我不确定我是否能够将其分叉给标准用户,或者这是否是我的请求的错误。如果我可以提供更多信息,请告诉我(这里是第一篇文章,所以对惯例有点不熟悉)。谢谢!

api rest github github-api

5
推荐指数
1
解决办法
5821
查看次数

无法在Startup.cs中保存ConfigurationSection - Web API

我无法在启动时将我的自定义保存ConfigurationSection在我的web.config文件中.

我已经按照本教程进行了通用实现.我的单元测试通过了,我能够ConfigurationSection在单元测试中保存de !

在应用程序启动时,我想ClaimCollection基于控制器类名和所属方法名建立一个:

Startup.cs

public void Configuration(IAppBuilder app)
{

    Config = new HttpConfiguration();

    BuildUnityContainer();

    BuildClaimCollection(); <----------------

    ConfigureOAuth(app);

    WebApiConfig.Register(Config);
    app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    app.UseWebApi(Config);

}

public void BuildClaimCollection()
{

    //config section
    MethodClaimSection methodClaimSection = BaseConfigurationSection<MethodClaimSection>.Open();

    var methods = GetClaimAuthorizedMethods();

    foreach (var method in methods)
    {
        var claimValue = GetClaimValueFromMethodName(method);
        var claim = new MethodClaimElement()
        {
            Type = "Method",
            Value = claimValue
        };

        methodClaimSection.MethodClaims.Add(claim);
    }
    methodClaimSection.Save();
}  
Run Code Online (Sandbox Code Playgroud)

BaseConfigurationSection.cs

public abstract class BaseConfigurationSection<T> : ConfigurationSection …
Run Code Online (Sandbox Code Playgroud)

c# configurationsection asp.net-web-api

5
推荐指数
0
解决办法
701
查看次数

使用loopbackjs添加嵌套的远程方法

我正在使用strongloop的loopbackjs来实现API.

对于Cat我定义了远程方法的模型,我们可以调用它meow.

所以我能做到:

GET /cats/{:id}/meow

Cat模型属于该User模型.

现在我希望能够做到这样的事情:

GET /users/{:id}/cats/{:id}/meow

有谁知道如何做到这一点?

我已经尝试过nestRemoting,它只适用于嵌套的"蓝图"方法.

loopbackjs

5
推荐指数
1
解决办法
534
查看次数

在类名前面添加下划线是确保类在库外部不可用的正确方法吗?

如果我在库中定义了一个辅助类,但我不想在库外部使用它,那么在类名前面放置下划线的正确隐藏机制是否正确?

part of foo;

class Bar { } // made available to users of the foo library

class _BarHelp { } // hidden from users of the foo library
Run Code Online (Sandbox Code Playgroud)

或者是否有其他隐藏 BarHelp 的方法?

dart

5
推荐指数
1
解决办法
502
查看次数

创建文件后删除文件

所以我正在创建 dll 类型文件,运行它们,然后我想删除它们。

然而,当我尝试删除它们时,我得到一个异常,因为它声称它们仍在被另一个进程使用。

我假设用于创建文件的代码没有正确处理资源以允许删除文件,这是我创建文件的代码。

if (!Directory.Exists(PathToRobots + Generation))
{
    Directory.CreateDirectory(PathToRobots + Generation);
}

File.WriteAllText(Path.Combine(PathToRobots + Generation, NameSpace + GetRobotName() + robotNumber + ".cs"), code);


CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters()
{
    GenerateInMemory = false,
    GenerateExecutable = false, // True = EXE, False = DLL
    IncludeDebugInformation = true,
    OutputAssembly = Path.Combine(FileName + ".dll") // Compilation name
};

parameters.ReferencedAssemblies.Add(@"robocode.dll");

CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);

if (results.Errors.HasErrors)
{
    StringBuilder sb = new StringBuilder();

    foreach (CompilerError error in results.Errors) …
Run Code Online (Sandbox Code Playgroud)

c# file

5
推荐指数
1
解决办法
215
查看次数

在xunit中实例化IOptions <>

我正在尝试为一个类(在.net Core项目中)编写一个xunit测试,它看起来像:

public Class FoodStore:IFoodStore
{
    FoodList foodItems;

    public FoodStore(IOptions<FoodList> foodItems)
    {
        this.foodItems = foodItems;
    }

    public bool IsFoodItemPresentInList(string foodItemId)
    {
        //Logic to search from Food List
    }
}`
Run Code Online (Sandbox Code Playgroud)

注意:FoodList实际上是一个包含数据的json文件,它在Startup类中加载和配置.

如何编写带有适当依赖注入的xunit测试来测试IsFoodItemPresentInList方法?

dependency-injection xunit xunit.net asp.net-core asp.net-core-1.0

5
推荐指数
4
解决办法
2381
查看次数

来自FxCop的哪条规则会停用?

我个人还没有使用FxCop.我们希望在进行代码分析之前先完成单元测试.但是,你会永久停用哪些规则?您会暂时停用哪些规则以及在哪种情况下停用?

code-analysis fxcop rules

4
推荐指数
1
解决办法
1033
查看次数

与ngMouseover辩论

我有这个HTML div,它使用该ngMouseover指令通过函数从api获取一些数据,如下所示:

标记:

<div ng-mouseover="getData()">
</div> 
Run Code Online (Sandbox Code Playgroud)

控制器:

$scope.getData = function() {
    //get data from api
}
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以在ngMouseover指令中添加延迟,这样只有在光标在div上停留几秒后才会触发它?就像它debounce在里面一样ngModelOptions.

javascript angularjs angularjs-directive

4
推荐指数
1
解决办法
1546
查看次数

将UserManager传递给ConfigureServices MVC 6中的AuthorizationHandler

给出以下用于UserManager的DI类

public class AccountAuthorizationHandler : AuthorizationHandler<OperationAuthorizationRequirement, AuthorisedAccount>
{
    private readonly UserManager<ApplicationUser> userManager;
    public AccountAuthorizationHandler(UserManager<ApplicationUser> userManager)
    {
        this.userManager = userManager;
    }
    protected override void Handle(AuthorizationContext context,
                                   OperationAuthorizationRequirement requirement,
                                   AuthorisedAccount resource)
    {
        // Pull the user ID claim out from the context.User
        var userId = context.User.GetUserId();
        // Get the current user's account numbers.       
        var user = userManager.Users
            .Include(u => u.AuthorisedAccounts)
            .Where(u => u.Id == userId)
            .FirstOrDefault();

        //Now check if the user's account numbers match the resource accountNumber, and 
        foreach( var authorizedAccount in …
Run Code Online (Sandbox Code Playgroud)

authorization dependency-injection asp.net-core-mvc

4
推荐指数
1
解决办法
1465
查看次数