小编ajr*_*ajr的帖子

Entity-framework-7将Fluent API配置组织到一个单独的类中

我很熟悉如何将流畅的API配置组织到EF6上的单独类中,但是如何通过EF7实现这一点?

以下是如何使用EF6执行此操作的示例:

ModelConfigurations.cs

public class ModelConfigurations : EntityTypeConfiguration<Blog>
{
     ToTable("tbl_Blog");
     HasKey(c => c.Id);
// etc..
}
Run Code Online (Sandbox Code Playgroud)

并从OnModelCreating()调用它

    protected override void OnModelCreating(DbModelbuilder modelBuilder)
    {
          modelBuilder.Configurations.Add(new ModelConfigurations());
// etc...
    }
Run Code Online (Sandbox Code Playgroud)

在EF7上,我无法解析EntityTypeConfiguration?从单独的类实现流畅的API调用的正确方法是什么?

c# entity-framework ef-fluent-api

6
推荐指数
1
解决办法
2938
查看次数

实体框架父 -&gt; 子链接和外键约束失败错误

我正在使用实体框架 7(核心)和 Sqlite 数据库。当前使用comboBox通过此方法更改实体类别:

/// <summary>
/// Changes the given device gategory.
/// </summary>
/// <param name="device"></param>
/// <param name="category"></param>
public bool ChangeCategory(Device device, Category category)
{
    if (device != null && category != null )
    {
        try
        {
            var selectedCategory = FxContext.Categories.SingleOrDefault(s => s.Name == category.Name);
            if (selectedCategory == null) return false;
            if (device.Category1 == selectedCategory) return true;

            device.Category1 = selectedCategory;
            device.Category = selectedCategory.Name;
            device.TimeCreated = DateTime.Now;
            return true;
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException("Category change for …
Run Code Online (Sandbox Code Playgroud)

c# sqlite foreign-key-relationship entity-framework-core

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

为什么 dotnet 测试工具没有创建代码覆盖率报告?

我的项目结构如下:

.
??? Application
??? Application.Core
??? Application.Domain
??? Application.Tests
??? Application.IntegrationTests
??? README.md
Run Code Online (Sandbox Code Playgroud)

运行我的测试的命令我使用以下输入:

dotnet test $folder.FullName -c Release --no-build /p:CoverletOutput='$root\coverage' /p:MergeWith='$root\coverage.json' /p:CoverletOutputFormat=opencover 
Run Code Online (Sandbox Code Playgroud)

这里$folder是指向我Application.Tests路径:C:\projects\coredemoapp\CoreDemoApp.Tests$rootC:\projects\coredemoapp\

所有测试都成功运行。然而,问题是,coverage.json也不是coverage.opencover.xml没有创建的文件。

我也尝试coverlet直接使用以下命令:

coverlet <path to test.dll> -
-target "dotnet" --targetargs "test --no-build" --merge-with $root\coverage.json --format opencover
Run Code Online (Sandbox Code Playgroud)

,一切都在我的本地机器上运行,并具有指向 dll 的显式路径。但是,在使用前一个$folder.FullName作为运行命令的情况下<path to assembly>,coverlet 假定调试dll的路径,而不是它应该的发布版本并且失败。

链接到完整的构建脚本

powershell dotnet-test coverlet

3
推荐指数
1
解决办法
3212
查看次数