如何使用EF Code First映射表拆分?例如,这里描述了EDMX的表分裂.它允许将具有1:1关系的两个实体映射到同一个表中.我知道我可以使用实体和复杂类型进行类似的映射,但最大的区别是复杂类型不能延迟加载(或根本不加载),这是表拆分的主要原因.
.net entity-framework poco ef-code-first entity-framework-4.1
有什么问题我可以问自己我们的设计,以确定我们是否应该在我们的应用程序中使用DTO或自我跟踪实体?
以下是我所知道的一些需要考虑的事项:
那么,我怎样才能确定哪些适合我们?我之前从未使用EF,所以我真的不知道STE是否适合我们.
我见过人们建议从STE开始,只有当它成为一个问题时才实施DTO,但是我们目前有DTO并且正在尝试决定使用STE是否会让生活变得更轻松.我们在这个过程中已经足够早,切换不会花费太长时间,但我不想切换到STE只是为了发现它对我们不起作用并且必须切换回来.
wcf poco n-tier-architecture entity-framework-4 self-tracking-entities
EF 4.1 RC.我想在实体添加/附加到DBContext后运行一些代码.是否有事件(我找不到).基本上我想检查添加/附加的实体是否属于某个界面,如果是,请用它做一些事情.谢谢!
当数据库中的值(位)设置为NULL时,如何设置默认值.现在我收到一个错误,告诉我从数据库加载bool时它不能为NULL.
谢谢.
在我的Global.asax中,我有以下几行:
Database.SetInitializer<myDbSupport>
(new DropCreateDatabaseIfModelChanges<myDbSupport>());
Run Code Online (Sandbox Code Playgroud)
如果我没有这个,那么当我更改模型时,sdf数据库将没有正确的结构.这在开发环境中是可以的,但是当我转向生产并希望更新数据库结构时,我当然不能放弃表,并丢失数据.
是否可以编写数据库更改脚本,并在部署具有更改结构的模型之前运行此更新?
我正在使用MVC和实体框架.我在我的模型文件夹中创建了一个类,下面是这个代码.我不断收到上面的错误消息以及下面的两个查询.我知道引用非标量变量存在一个已知问题,但我不确定如何实现变通方法:
http://msdn.microsoft.com/en-us/library/bb896317.aspx#Y1442
private MovieLibraryDBEntities movieLibraryDBEntitiesContext;
public int getNumberOfEntriesReserved()
{
return (from m in movieLibraryDBEntitiesContext.Movies
where m.CheckedOut.Equals(1)
select m).Count();
//return movieLibraryDBEntitiesContext.Movies
// .Where(e => e.CheckedOut.Equals(1))
// .Select (e => e.Title).Count();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在WCF服务中使用二进制消息编码,遵循此站点上的许多示例.
在服务器上,我将绑定声明为:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
<readerQuotas maxDepth="32" maxStringContentLength="4096000"
maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
该服务设置为使用它(我认为):
<service behaviorConfiguration="MyService.ServiceBehavior" name="MyService.ContentUploadService">
<endpoint
address=""
binding="customBinding"
bindingConfiguration="binaryHttpBinding"
contract="MyService.IContentUpload"
name="MyService.ContentUploadService" />
Run Code Online (Sandbox Code Playgroud)
客户端具有相同的声明:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
<readerQuotas maxDepth="32" maxStringContentLength="4096000"
maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
和:
<endpoint
address="http://foo.com/ContentUploadService.svc"
binding="customBinding"
bindingConfiguration="binaryHttpBinding"
contract="MyService.IContentUpload"
name="MyService.ContentUploadService"/>
Run Code Online (Sandbox Code Playgroud)
客户端似乎正在工作,但服务器抛出一个异常,表明绑定不到位:
内容类型application/soap + msbin1被发送到期望text/xml的服务; 字符集= UTF-8.客户端和服务绑定可能不匹配.
在日志文件中出现此错误之前,就会在尝试打开服务主机时抛出此错误,这必须是原因.
找不到配置评估上下文.
我为此消息尝试的搜索链接都没有帮助.那么,我错过了什么基本文章?
是否可以仅使用数据注释在Entity Framework 4.1(Code First方法)中定义多对多关系,而无需使用模型构建器?
例如,类似于:
Product = { Id, Name, ... }
Category = { Id, Name, ... }
ProductCategory = { ProductId, CategoryId }
Run Code Online (Sandbox Code Playgroud)
你得到了照片.
我不希望ProductCategory在上下文中有两个多对一的中间实体,因为我没有任何额外的数据,只有两个FK.此外,我应该能够为中间表定义表名,以便与现有数据库一起使用.
entity-framework code-first data-annotations ef-code-first entity-framework-4.1
据我所知,Entity Framework实现了Identity Map Pattern,因此EF会在内存中缓存一些实体.
我举个例子吧.
var context = new StudentContext();
var student = context.Students.Where(st => st.Id == 34).FirstOrDefault();
// any way of changing student in DB
var anotherContext = new StudentContext();
var anotherStudent = anotherContext.Students.Where(st => st.Id == 34).FirstOrDefault();
anotherStudent.Name = "John Smith";
anotherContext.SaveChanges();
student = context.Students.Where(st => st.Id == 34).FirstOrDefault();
// student.Name contains old value
Run Code Online (Sandbox Code Playgroud)
有没有办法使第一个上下文的缓存无效并检索新student实体而无需重新创建上下文?
感谢帮助.
.net caching entity-framework identity-map entity-framework-4
我有一个类库项目,我的DbContext和迁移启用了以下配置文件:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="DataContext" connectionString="Data Source=Data.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在我使用此项目的迁移之前的某个时间,Get-Migrations命令总是返回给我:
PM> Get-Migrations -StartupProjectName "Data"
Retrieving migrations that have been applied to the target database.
201207012104355_Initial
201207012031234_Initial
201207012024250_Initial
Run Code Online (Sandbox Code Playgroud)
问题是命令总是返回这些项,即使我删除Data.sdf或删除所有项目并创建新项目.我可以创建新数据库的唯一方法是将连接字符串中的数据库文件名从Data.sdf更改为Data1.sdf.那么如何在不更改数据库名称的情况下重置迁移历史?
.net ×4
c# ×2
code-first ×2
poco ×2
wcf ×2
asp.net ×1
bit ×1
boolean ×1
caching ×1
database ×1
default ×1
identity-map ×1
null ×1
wcf-binding ×1