实体框架4是否订购了集合?
例如,我的Order有一个属性是OrderItems的集合,但顺序很重要,我宁愿在访问它们之前不对它们进行排序.
有关示例,请参阅Nhibernate:NHibernate中的 List vs Set vs Bag
我在我的项目中使用EntityFramework POCO +代理+延迟加载.今天,我很奇怪为什么看到该类Transaction具有其相关集合Rows物化到HashSet(而不是EntityCollection).我需要EntityCollection跟踪集合中的更改.
public class Transaction
{
public virtual ICollection<TransactionRow> Rows { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然而,其他实体类将其相关集合具体化EntityCollection.
我正在加载Transaction通过ObjectQuery,所以它应该在上下文中.还创建了对象的代理.
任何人都可以告诉 - 实体框架如何决定使用什么 - HashSet或EntityCollection?为什么有些东西会成为HashSets?
entity-framework poco hashset entity-framework-4 entitycollection
我使用Entity Framework 4.0创建了一个使用模型优先方法的数据库模型.然后我使用模型生成数据库创建了一个sql脚本...我还在App_Data文件夹中创建了一个SQL Server数据库文件.我现在如何针对此MDF文件运行SQL文件?
我正在使用Visual Studio 2010.
我不想手动将每个映射类添加到ModelBuilder()中,因此尝试使用我有限的反射知识来注册它们.这就是我所拥有的,这是我得到的错误:
码:
private static ModelBuilder CreateBuilder() {
var contextBuilder = new ModelBuilder();
IEnumerable<Type> configurationTypes = typeof(DatabaseFactory)
.Assembly
.GetTypes()
.Where(type => type.IsPublic && type.IsClass && !type.IsAbstract && !type.IsGenericType && typeof(EntityTypeConfiguration).IsAssignableFrom(type) && (type.GetConstructor(Type.EmptyTypes) != null));
foreach (var configuration in configurationTypes.Select(type => (EntityTypeConfiguration)Activator.CreateInstance(type)))
{
contextBuilder.Configurations.Add(configuration);
}
return contextBuilder;
}
Run Code Online (Sandbox Code Playgroud)
错误: 错误2无法从用法推断出方法'System.Data.Entity.ModelConfiguration.Configuration.ConfigurationRegistrar.Add(System.Data.Entity.ModelConfiguration.EntityTypeConfiguration)'的类型参数.尝试显式指定类型参数.C:\ root\development\playground\PostHopeProject\PostHope.Infrastructure.DataAccess\DatabaseFactory.cs 67 17 PostHope.Infrastructure.DataAccess
持久性无知是指能够允许开发人员以完全独立于基础结构服务(在本例中为实体框架)的基本要求和假设的方式编写和测试域对象.此类要求/假设通常包括:
- 需要实现特定的接口(例如,IPOCO)
- 从基类继承
- 提供特定的构造函数
- 对象实例化/构造要求 - 例如使用特定工厂**
- 需要元数据或映射类或属性属性
- 需要使用特定的关系机制
这相当于能够使用普通旧CLR对象(POCO),以便开发人员可以创建其域对象,而不受框架强加的所有假设和要求的影响.使用此方法,一旦域对象准备满意,开发人员就可以将这些类与实体框架一起使用,以便进行关系数据库访问和持久性.
截至目前(CTP5),有没有办法使用参数化构造函数重建poco?如果没有,很难看出实体框架如何被称为提供持久性无知.
domain-driven-design entity-framework poco code-first entity-framework-4
嗨我目前正在使用.sdf数据库(服务器精简版4.0)和SQL快递.我试图在同一个表(类别 - 子类别)上设置级联删除,但我得到了我不能添加到同一个表的关系.
外键约束具有和更新或删除级联规则,并且不允许自引用同一表中的列
我该怎么办?
编辑
我是唯一一个有这个问题的人吗?
我们有一个ASP.Net MVC应用程序,它使用EF4作为其数据访问层,我们看到当我们认为它们应该是没有抛出OptimisitcConcurrencyExceptions时的意外行为.
我们已将问题简化为以下代码...
using System.Linq;
using Project.Model;
namespace OptimisticConcurrency
{
class Program
{
static void Main()
{
Contact firstContact = null;
using (var firstEntities = new ProjectEntities())
{
firstContact = (from c in firstEntities.Contacts
where c.LastName == "smith" select c).Single();
}
using (var secondEntities = new ProjectEntities())
{
var secondContact = (from c in secondEntities.Contacts
where c.LastName == "smith" select c).Single();
secondContact.Title = "a";
secondEntities.SaveChanges();
}
firstContact.Title = "b";
using (var thirdEntities = new ProjectEntities())
{
var thirdContact = (from …Run Code Online (Sandbox Code Playgroud) 我是一名NHibernate开发人员,试图在一个爱好项目中为Entity Framework提供一个机会.我习惯使用Fluent NHibernate在代码中指定映射数据.赦免微软认为不应允许开发人员编写代码的信念,我试图使用Entity Framework的可视化设计器表面(通过在Visual Studio中打开.edmx文件获得)来创建映射.
我不知道如何建立多对多的关系!我已经从数据库"更新了模型",但是我得到了两个一对多的关系,这个关系是一个对应于联结表的新实体(它只包含外键和它自己的主键).
到目前为止,所有尝试通过点击实体和关系来解决这个问题都失败了.任何人都可以给我指针吗?
我是.NET实体框架的新手,我正在尝试迭代数百万行的表中的记录.这是基本代码:
// select the records from the database
var records = from data in dataContext.Messages
select data;
// iterate over the messages
foreach (var record in records)
{
// do nothing
}
Run Code Online (Sandbox Code Playgroud)
在迭代数据时,我得到了"outofmemoryexception".有什么方法可以改变我的查询或管理ObjectQuery实例的内存?
我一直在使用一些LINQ over Entities,我得到了奇怪的结果,我想得到解释......
给出以下LINQ查询,
// Sample # 1
IEnumerable<GroupInformation> groupingInfo;
groupingInfo = from a in context.AccountingTransaction
group a by a.Type into grp
select new GroupInformation()
{
GroupName = grp.Key,
GroupCount = grp.Count()
};
Run Code Online (Sandbox Code Playgroud)
我得到以下SQL查询(取自SQL Profiler):
SELECT
1 AS [C1],
[GroupBy1].[K1] AS [Type],
[GroupBy1].[A1] AS [C2]
FROM ( SELECT
[Extent1].[Type] AS [K1],
COUNT(1) AS [A1]
FROM [dbo].[AccountingTransaction] AS [Extent1]
GROUP BY [Extent1].[Type]
) AS [GroupBy1]
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
如果我将我的LINQ查询更改为:
// Sample # 2
groupingInfo = context.AccountingTransaction.
GroupBy(a => a.Type).
Select(grp => new GroupInformation() …Run Code Online (Sandbox Code Playgroud) c# linq entity-framework entity-framework-4 entity-framework-6
.net ×3
c# ×3
code-first ×2
poco ×2
hashset ×1
linq ×1
many-to-many ×1
mdf ×1
orm ×1
reflection ×1
sql-scripts ×1