我正在将我的项目从数据库优先迁移到代码优先.
实体框架做了一些很好的工作来创建我的新数据库(应该模仿旧的数据库).
我正在使用数据注释和流畅的API组合来描述我的表.
我的数据库有一些索引,我也希望实体框架能够创建它们.看来,执行此操作的旧方法是定义自己的初始化程序并使用自定义T-SQL.
但是现在我们有了EF迁移,它应该更容易实现.
我似乎无法弄清楚如何将CreateDatabaseIfNotExists <>与自动迁移相结合来创建索引.我尝试使用MigrateDatabaseToLatestVersion <,>但在创建数据库后似乎没有执行迁移.
现在我们有Entity Framework 4.3,在数据库创建上创建索引和约束的正确方法是什么?
我开始一个新项目,我需要创建一个项目来实现Entity Framework 4.0和Unity Framework 2.0以及Enterprise Library 5.0.
我是Entity Framework和Unity Framework的新手,并且对如何使用数据库获取正常的Object BO和DAL感到困惑.
有人能指出我在同一个项目中开始的一些简单例子.后来我需要将ASP.NET MVC 2.0用于UI.
我已经看过Julie Lerman的视频实体框架我可以将桌子作为实体获得,但之后我不知道Unity,Enterprise Library将适用于哪里.之后我迷失了.
有人请帮助我.
asp.net-mvc entity-framework enterprise-library unity-container
我有以下3个表格:
CREATE TABLE [dbo].[Items](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL)
CREATE TABLE [dbo].[Params](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[DisplayName] [nvarchar](50) NOT NULL)
CREATE TABLE [dbo].[Params2Items](
[ParamID] [int] NOT NULL,
[ItemID] [int] NOT NULL,
[ID] [int] IDENTITY(1,1) NOT NULL)
Run Code Online (Sandbox Code Playgroud)
和2个相应的类
public class Item
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<ItemParameter> Params { get; set; }
}
public class ItemParameter
{
public int ID …Run Code Online (Sandbox Code Playgroud) 我正在尝试初始化EFUnitOfWorkFactory对象上下文.
在global.asax中:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
ObjectFactory.Initialize(x =>
{
x.For<IUnitOfWorkFactory>().Use<EFUnitOfWorkFactory>();
x.For(typeof(IRepository<>)).Use(typeof(EFRepository<>));
}
);
EFUnitOfWorkFactory.SetObjectContext(() => new MyEntities());
}
Run Code Online (Sandbox Code Playgroud)
在生成的Object上下文中,我有:
public partial class MyEntities : ObjectContext
{
.....
.....
}
Run Code Online (Sandbox Code Playgroud)
我在执行Web应用程序时遇到异常EFUnitOfWorkFactory.SetObjectContext(() => new MyEntities());:
Compiler Error Message: CS0012: The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Run Code Online (Sandbox Code Playgroud)
我将System.Data.Entity添加到我的Web应用程序两次并重建但仍然收到此消息.另外,gobal.asax中的这一行有时标有红色下划线.
有谁知道如何解决这个问题?
我有一个基于Codefirst EF-4.1的程序.用户获取上下文并可以修改某些属性.用户完成后,我会快速完成
ChangeTracker.Entries().Any(e => e.State != EntityState.Unchanged);
Run Code Online (Sandbox Code Playgroud)
确定是否SaveChanges()需要a .如果我执行"SaveChanges()"调用,则所做的更改将持久保存到数据库中.
这适用于某些属性,不适用于其他属性.具体来说,它似乎适用于简单类型float和集合层次结构ObservableCollection.
难道我做错了什么?
我有一个wcf restful服务并正在运行。如果使用WebServiceHost启动Web服务,则可以毫无问题地发出Get / Post。我尝试将wcf服务移至本地机器上的IIS 7.5,但似乎无法正常进行。
我尝试从wcf服务调用任何内容时都收到以下错误消息:(http:// wp9dbytr1k1:8081 / service.svc / AnythingHereForGETorPUT)。我在虚拟目录/设备中尝试过,但遇到了同样的问题。
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
Run Code Online (Sandbox Code Playgroud)
如果我直接调用svc文件(http:// wp9dbytr1k1:8081 / service.svc),它会很高兴并告诉我
“您已经创建了一个服务。要测试该服务,您将需要创建一个客户端并使用它来调用该服务。您可以使用以下语法从命令行使用svcutil.exe工具来执行此操作:svcutil.exe …
我有两节课:
public class User
{
public int Id {get;set;}
public string Username {get;set;}
[InverseProperty("Users")]
public virtual ICollection<Tag> Tags {get;set;}
}
public class Tag
{
public int Id {get;set;}
public string Title {get;set;}
[InverseProperty("Tags")]
public virtual ICollection<User> Users {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
这显然导致第3个表类似于称为UserTags的多对多关系,它只有两列,UserId和TagId.
现在假设我有100.000个用户和100.000个标签,平均每个Eser与1.000个标签有关系.我想从特定的User.Tags集合中删除单个标记,而不必在此之前加载所有标记.
最快的方法是什么?
many-to-many entity-framework entity-framework-4 entity-framework-5
code-first ×2
.net ×1
ado.net ×1
asp.net ×1
asp.net-mvc ×1
iis ×1
iis-7.5 ×1
indexing ×1
many-to-many ×1
rest ×1
wcf ×1