- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在开发 ASP.NET Core 5.0 应用程序 - 我尝试将该应用程序从 SqLite DB 提供程序迁移到 CosmosDb。我使用 Entity Framework Core
“Microsoft.EntityFrameworkCore”版本=“5.0.7”
“Microsoft.EntityFrameworkCore.Cosmos”版本=“5.0.7”
我使用“Azure Cosmos DB 模拟器”或“真正的 azure 数据库实例”,没有区别。执行 .SaveChanges()
时,Visual Studio 2019 输出窗口中有日志行:
抛出异常:
'System.FormatException' in System.Private.CoreLib.dll
Exception: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
我创建了一个文件单元测试项目来演示:
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Threading.Tasks;
namespace UnitTestCosmos
{
[TestClass]
public class UnitTestCosmosDb
{
[TestMethod]
public async Task TryWriteDataAsync()
{
using (var destinationcontext = new MyDbContext())
{
var item = new MyVerbrauch(){MessId = Guid.NewGuid(), StromHausKwh = 357};
Debug.WriteLine($"Try Write ");
try
{
await destinationcontext.MyVerbrauch.AddAsync(item);
Debug.WriteLine($"\nSave to MyDbContext\n");
await destinationcontext.SaveChangesAsync(); // throws ??
}
catch (Exception ex)
{
Debug.WriteLine($"Exception: {ex.Message}");
}
}
}
}
public class MyVerbrauch
{
[Key]
[Required]
public Guid MessId { get; set; }
[Required]
public int StromHausKwh { get; set; }
}
public class MyDbContext : DbContext
{
public DbSet<MyVerbrauch> MyVerbrauch { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Use Cosmos DB
optionsBuilder.UseCosmos("https://localhost:8081",
"< your key>",
databaseName: "CosmosDBdemo.cdb");
}
}
}
这是我关于堆栈溢出的第一个问题,我将不胜感激任何帮助!!
7 月 15 日添加:
Visual Studio 输出窗口:
Save to MyDbContext
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Net.Security.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Security.Cryptography.X509Certificates.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Security.Cryptography.Primitives.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'E:\Andreas\git\CosmosDbTest\CosmosDbTest\bin\Debug\net5.0\System.Configuration.ConfigurationManager.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Net.WebClient.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Net.ServicePoint.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Buffers.dll'.
DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://localhost:8081/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Collections.NonGeneric.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Security.Principal.Windows.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Security.Claims.dll'. Symbols loaded.
'testhost.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Security.Cryptography.Encoding.dll'. Symbols loaded.
DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations
DocDBTrace Information: 0 : Current WriteEndpoints = (https://127.0.0.1:8081/) ReadEndpoints = (https://127.0.0.1:8081/)
DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1
DocDBTrace Information: 0 : RntbdConnectionDispenser: requestTimeoutInSeconds: 10, openTimeoutInSeconds: 5, timerValueInSeconds: 1
DocDBTrace Information: 0 : Creating RNTBD TransportClient with options Rntbd.TransportClient.Options
OpenTimeout: 00:00:05
RequestTimeout: 00:00:10
TimerPoolResolution: 00:00:01
MaxChannels: 65535
PartitionCount: 1
MaxRequestsPerChannel: 30
ReceiveHangDetectionTime: 00:01:05
SendHangDetectionTime: 00:00:10
IdleTimeout: -00:00:01
EnableCpuMonitor: True
UserAgent: cosmos-netstandard-sdk/3.12.0|3.11.4|01|X64|Microsoft Windows 10.0.19041|.NET 5.0.7| Microsoft.EntityFrameworkCore.Cosmos/5.0.7 Suffix: Microsoft.EntityFrameworkCore.Cosmos/5.0.7
CertificateHostNameOverride:
DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1
DocDBTrace Information: 0 : CpuMonitor started
The thread 0x44c4 has exited with code 0 (0x0).
Exception thrown: 'System.FormatException' in System.Private.CoreLib.dll
DocDBTrace Information: 0 : CpuMonitor started
The thread 0x1f2c has exited with code 0 (0x0).
Exception thrown: 'System.FormatException' in System.Private.CoreLib.dll
DocDBTrace Information: 0 : Opened 1 channels to server rntbd://127.0.0.1:10253/
DocDBTrace Information: 0 : Awaiting RNTBD channel initialization. Request URI: rntbd://127.0.0.1:10253/apps/DocDbApp/services/DocDbServer20/partitions/a4cb4960-38c8-11e6-8106-8cdcd42c33be/replicas/1p/
DocDBTrace Information: 0 : RNTBD: ConnectUnicastPortAsync connecting to rntbd://127.0.0.1:10253/ (address 127.0.0.1)
DocDBTrace Information: 0 : RNTBD connection established 127.0.0.1:51807 -> 127.0.0.1:10253
DocDBTrace Information: 0 : RNTBD SSL handshake complete 127.0.0.1:51807 -> 127.0.0.1:10253
The thread 0x27cc has exited with code 0 (0x0).
The thread 0x1904 has exited with code 0 (0x0).
The program '[17280] testhost.exe' has exited with code 0 (0x0).
和调用堆栈
System.Private.CoreLib.dll!System.Convert.FromBase64CharPtr(char* inputPtr, int inputLength) Line 2776 C#
System.Private.CoreLib.dll!System.Convert.FromBase64String(string s) Line 2568 C#
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.ResourceId.FromBase64String(string s) Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.ResourceId.Verify(string id, out byte[] buffer) Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.ResourceId.TryParse(string id, out Microsoft.Azure.Documents.ResourceId rid) Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.PathsHelper.TryParsePathSegmentsWithDatabaseAndCollectionNames(string resourceUrl, out bool isFeed, out string resourcePath, out string resourceIdOrFullName, out bool isNameBased, out string databaseName, out string collectionName, string clientVersion, bool parseDatabaseAndCollectionNames) Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.DocumentServiceRequest.DocumentServiceRequest(Microsoft.Azure.Documents.OperationType operationType, Microsoft.Azure.Documents.ResourceType resourceType, string path, System.IO.Stream body, Microsoft.Azure.Documents.AuthorizationTokenType authorizationTokenType, Microsoft.Azure.Documents.Collections.INameValueCollection headers) Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.DocumentServiceRequest.Create(Microsoft.Azure.Documents.OperationType operationType, Microsoft.Azure.Documents.ResourceType resourceType, string relativePath, Microsoft.Azure.Documents.AuthorizationTokenType authorizationTokenType, Microsoft.Azure.Documents.Collections.INameValueCollection headers) Unknown
Microsoft.Azure.Cosmos.Client.dll!Microsoft.Azure.Cosmos.Routing.ClientCollectionCache.ReadCollectionAsync(string collectionLink, System.Threading.CancellationToken cancellationToken, Microsoft.Azure.Cosmos.IDocumentClientRetryPolicy retryPolicyInstance) Line 61 C#
Microsoft.Azure.Cosmos.Client.dll!Microsoft.Azure.Cosmos.Routing.ClientCollectionCache.GetByNameAsync.AnonymousMethod__0() Line 52 C#
Microsoft.Azure.Cosmos.Client.dll!Microsoft.Azure.Cosmos.TaskHelper.InlineIfPossible.AnonymousMethod__0() Line 67 C#
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.BackoffRetryUtility<System.__Canon>.ExecuteAsync.AnonymousMethod__0() Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.BackoffRetryUtility<Microsoft.Azure.Cosmos.ContainerProperties>.ExecuteRetryAsync(System.Func<System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerProperties>> callbackMethod, System.Func<System.Exception, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.Azure.Documents.ShouldRetryResult>> callShouldRetry, System.Func<System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerProperties>> inBackoffAlternateCallbackMethod, System.TimeSpan minBackoffForInBackoffCallback, System.Threading.CancellationToken cancellationToken, System.Action<System.Exception> preRetryCallback) Unknown
Microsoft.Azure.Cosmos.Direct.dll!Microsoft.Azure.Documents.BackoffRetryUtility<Microsoft.Azure.Cosmos.ContainerProperties>.ExecuteAsync(System.Func<System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerProperties>> callbackMethod, Microsoft.Azure.Documents.IRetryPolicy retryPolicy, System.Threading.CancellationToken cancellationToken, System.Action<System.Exception> preRetryCallback) Unknown
Microsoft.Azure.Cosmos.Client.dll!Microsoft.Azure.Cosmos.TaskHelper.InlineIfPossible<Microsoft.Azure.Cosmos.ContainerProperties>(System.Func<System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerProperties>> function, Microsoft.Azure.Documents.IRetryPolicy retryPolicy, System.Threading.CancellationToken cancellationToken) Line 80 C#
Microsoft.Azure.Cosmos.Client.dll!Microsoft.Azure.Cosmos.Routing.ClientCollectionCache.GetByNameAsync(string apiVersion, string resourceAddress, System.Threading.CancellationToken cancellationToken) Line 51 C#
Microsoft.Azure.Cosmos.Client.dll!Microsoft.Azure.Cosmos.Common.CollectionCache.ResolveByNameAsync.AnonymousMethod__0() Line 253 C#
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerProperties>>.InnerInvoke() Line 497 C#
System.Private.CoreLib.dll!System.Threading.Tasks.Task..cctor.AnonymousMethod__277_0(object obj) Line 2359 C#
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 274 C#
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Line 2320 C#
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread threadPoolThread) Line 2258 C#
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteFromThreadPool(System.Threading.Thread threadPoolThread) Line 2243 C#
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 641 C#
System.Private.CoreLib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() Line 29 C#
最佳答案
我使用 CosmosDB(云)和 Cosmos DB 模拟器验证了上面评论中给出的结果。该问题是由选择的数据库名称引起的(它被设置为“CosmosDBdemo.cdb”)
尝试在“Microsoft.Azure.Documents.ResourceId.FromBase64String(string s)”中对该字符串进行 Base64 解码并引发异常。更改databaseName时不再出现异常。
解决方案似乎是:永远不要使用“.”在数据库名称中
关于c# - Entity Framework Core 5 在 SaveChanges() 中抛出 System.FormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68384790/
我有这些实体(这只是我为这篇文章创建的抽象): 语言 区 说明 这些是它们之间的引用: 区 * - 1 语言 说明 * - 1 语言 区 1 - 1 说明 如果我这样取: var myFetch =
经过大量谷歌搜索后,除了降级 hibernate 版本之外,我没有找到问题的答案。但我在 2003 年类似的帖子中遇到了这种情况。 问题是什么: //in the first session I d
我听说过 linq to entities 。 Entity Framework 是利用linq to entities吗? 最佳答案 LINQ to Entities 是 Entity Framew
我是 Entity Framework 和 ASP.Net MVC 的新手,主要从教程中学习,对任何一个都没有深入了解。 (我确实有 .Net 2.0、ADO.Net 和 WebForms 方面的经验
如果我编写 LINQ to Entities 查询,该查询是否会转换为提供程序理解的 native 查询(即 SqlClient)? 或者 它是否会转换为实体 SQL,然后 Entity Framew
这个问题已经有答案了: EF: Include with where clause [duplicate] (5 个回答) 已关闭 2 年前。 看来我无法从数据库中获取父级及其子级的子集。 例如...
我开始在一家新公司工作,我必须在一个旧项目上使用 C++ 工作。所以,我忘记了一些 C++ 本身的代码结构。在一个函数中,我在一个函数中有双冒号::,但我不知道如何理解它。 例如,我知道如果我有 EN
我写了一个方法来允许为 orderby 子句传递一个表达式,但我遇到了这个问题。 Unable to cast the type 'System.DateTime' to type 'System.I
简单的问题:LINQ to Entities 和 Entity Framework 有什么区别?到目前为止,我认为这两个名称是用来描述同一个查询的,但我开始觉得事实并非如此。 最佳答案 Entity
我想使用 Entity Framework 。但是,我还要求允许我的用户在我们的系统中定义自定义字段。我想仍然使用 Entity Framework ,而不是使用具有哈希表属性的分部类。 下面是我想到
我正在阅读这个 E.F. 团队博客的这个系列 http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-featu
我正在使用 EF6 开发插件应用程序,代码优先。 我有一个名为 User 的实体的主要上下文。 : public class MainDataContext : DbContext { pub
当我得到最后的 .edmx 时,我遇到了问题。 我收到一条消息说 错误 11007:未映射实体类型“pl_Micro”。 查看设计器 View ,我确实看到该表确实存在。 我怎样才能克服这个消息? 最
我已阅读与使用 Entity Framework 时在 Linq to Entities (.NET 3.5) 中实现等效的 LEFT OUTER JOIN 相关的所有帖子,但尚未找到解决以下问题的方
使用 WCF RIA 服务和 Entity Framework 4. 我有 3 个 DTO:学校、州、区。 州 DTO 有一个地区属性(property),其构成。学校 DTO 有一个国家属性(pro
我有一个 Employee 实体,它继承自一个继承自 Resource 实体(Employee -> Person -> Resource)的 Person 实体。是否可以通过编程方式获取 Emplo
我有一个使用 JPA 的 java 应用程序。 假设我有一个名为 Product 的实体与 name和 price属性(所有实体都有一个 id 属性)。 自然我可以得到一个List相当容易(来自查询或
我有一个 Entity Framework 类,其中有两个指向另一个对象的引用 public class Review { [Key] public int Id {get;s
我是 Symfony 2 的新手,我想知道一些事情: 假设我的项目中有 2 个 bundle 。我想在两个包中使用从我的数据库生成的实体。 我应该在哪里生成实体? (对我来说,最好的方法是在 bund
我想在具有方法和属性的部分类中扩展 EF 实体。我经常这样做。 但是现在我需要将来自该实体的数据与来自其他实体的数据结合起来。因此,我需要能够访问实体 objectcontext(如果附加)来进行这些
我是一名优秀的程序员,十分优秀!