如何在EF Core 1.1的本地数据中查询具有子孙子属性的父级?

时间:2017-01-03 09:49:30

标签: c# linq entity-framework-core

在将数据从旧系统导入新系统时,我需要查找包含其名称和属性而非ID的项目。此外,只有在所有内容都有效的情况下,才应保存整个导入集。所以我不能在处理不同实体之间进行保存。

我以前在EF6中使用此查询:

.container {background-color: transparent;
    width: 300px;
    height: 300px;
    border: 2px solid red;
    position: relative;
overflow: hidden;

/* Will stretch to specified width/height */
  background-size: 490px 500px;
  background-repeat: no-repeat;
}

如果我尝试使用Entity Framework Core 1.1运行它,我会收到以下错误:

  

发生System.ArgumentException HResult = -2147024809
  消息=字段   'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor + TransparentIdentifier <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script> <script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.min.js"></script> <script src="https://hongru.github.io/proj/canvas2image/canvas2image.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <link href='https://fonts.googleapis.com/css?family=Philosopher' rel='stylesheet' type='text/css'> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.js"></script> <script src="https://files.codepedia.info/uploads/iScripts/html2canvas.js"></script> <select id="imajes"> <option value="">Choose Image</option> <option value="dog">Dog</option> </select> <select id="dog" name="subselector" class="subselector" style="display:none"> <option value="">Choose an item</option> <option value="bulldog">Bulldog</option> <option value="huntingdog">Hunting Dog</option> <option value="policedog">German Shepherd</option> </select> <div id="firstshirt" class="container" style="float:left;"><div id="fotos" ><img class="modal-content" id="imgdisplay" /></div></div> <input id="btn-Preview-Image" type="button" value="Preview"/><a id="download" download="my_image.png" href="#">Download image</a> <h3>result:</h3> <div> <div id="previewImage"> </div><a id="download" download="my_image.png" href="#">Download image</a></div> <div style='display:none;' id="bulldogimges" class="smallimages"> <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif"> <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55"> </div> <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif"> <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55"> </div> <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/free-bulldog-clipart-031350.gif"> <img src="https://torcdesign.com/clipart/free-bulldog-clipart-031350.gif" alt="Smiley face" width="55" height="55"> </div> </div> 1 [Project.Models.MetaConcept]。内蒙古'   没有为类型定义   'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor + TransparentIdentifier`2 [Project.Models.MetaAttribute,Project.Models.MetaConcept]'   Source = System.Linq.Expressions StackTrace:          at System.Linq.Expressions.Expression.Field(Expression expression,FieldInfo field)InnerException:

此错误的含义是什么?使用EF 1.1进行此类查询的最佳做法是什么?

整个模型非常复杂,但这里是相关类的简化版本。 添加(实体类和配置):

      MetaAttribute fromAttribute =
                    db.Attributes
                    .Single(a =>
                        (a.Concept.Name.Equals(entityName)) &&
                        (a.Concept.System.Code.Equals(defaultSystem.Code)) &&
                        (a.Name.Equals(attributeName)))
                ??   db.Attributes.Local.Single(a => (a.Concept.Name == entityName) && (a.Concept.System.Code == defaultSystem.Code) && (a.Name == attributeName));

配置:

2[MetaUI.Models.MetaAttribute,System.Collections.Generic.IEnumerable

1 个答案:

答案 0 :(得分:4)

我的解决方案是从调试器中排除此异常。所以我对Visual Studio进行了过度调试。