簡體   English   中英

Azure Cosmos DB - StartIndex 不能小於零。 (參數'startIndex')

[英]Azure Cosmos DB - StartIndex cannot be less than zero. (Parameter 'startIndex')

我正在嘗試將一個氏族實體插入到氏族容器中。 我的分區鍵是id ,model 是這樣的:

public class Clan
{
    public string Id { get; set; }
    public string ClanName { get; set; }
    public int MembersCount { get; set; }
    public int Capacity { get; set; }
    public int WHP { get; set; }
    public int LogoId { get; set; }
    public AppMarketType AppMarket { get; set; }
}

氏族數據庫上下文:

public class ClanContext : DbContext
{
    public ClanContext(DbContextOptions<ClanContext> options)
        : base(options) { }

    public DbSet<Clan> Clans { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Clan>()
            .HasNoDiscriminator()
            .ToContainer("Clans")
            .HasPartitionKey(p => p.Id)
            .Property(x => x.Id).ToJsonProperty("id");
    }
}

我想做的就是:

try
{
    var clan = new Clan
    {
        Id = Guid.NewGuid().ToString(),
        AppMarket = Core.AppMarketType.GooglePlay,
        ClanName = "Blazers",
        Capacity = 110,
        LogoId = 342,
        MembersCount = 34,
        WHP = 1280
    };
    _clanContext.Add(clan);
    _clanContext.SaveChanges();
 }
 catch (Exception)
 {
     throw;
 }

它拋出一個異常:

StartIndex 不能小於零。 (參數'startIndex')

調用堆棧:

at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length)
at Microsoft.EntityFrameworkCore.Cosmos.ValueGeneration.Internal.IdValueGenerator.NextValue(EntityEntry entry)
at Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator.Next(EntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ValueGenerationManager.Generate(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry entry, EntityState entityState)
at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)
at Microsoft.EntityFrameworkCore.DbContext.Add[TEntity](TEntity entity)
at Dummy.Web.Services.ClanService.<IncreaseWHP>d__6.MoveNext() in C:\Repositories\dummysolution\Domain\dummydomain\Services\ClanService.cs:line 50
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Clans.JoinGroup.<Run>d__2.MoveNext() in C:\Repositories\dummysolution\API\dummyapi\Clans\JoinGroup.cs:line 55

與貢獻者確認后,此問題已在Microsoft.EntityFrameworkCore.Cosmos 5.0.0中修復。

如果您使用的是5.0.0之前的版本,請升級后再試。

如果您在 5.0.0 或更高版本中遇到類似的異常,請提交一個新問題並包括一個演示它的小項目。


相關問題:

無法在集合中創建新項目

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM