ctp4

EF CTP4 : “The context cannot be used while the model is being created.”

拜拜、爱过 提交于 2019-12-24 04:24:06
问题 I have two entities : Student and Class. they have a many-to-many relationship between each other : class Student { ICollection<Class> Classes{get;set;} } class Class { ICollection<Student> Students{get;set;} } when I try to execute the following statement : return _db.Students.Where(s => s.Email == email).FirstOrDefault(); I get this error message : "The context cannot be used while the model is being created." 回答1: I had same issue/exception when I forgot to put connection string from the

SQL CE 4 System.Transaction support

跟風遠走 提交于 2019-12-12 16:57:21
问题 A similar question was asked here but had no answer. I am attempting to use a System.Transactions.CommittableTransaction with EF CTP4 and SQL CE 4. I have created the following transaction attribute for my ASP.NET MVC Controller actions: public class TransactionAttribute : ActionFilterAttribute { CommittableTransaction transaction; public override void OnActionExecuting(ActionExecutingContext filterContext) { transaction = new CommittableTransaction(); Transaction.Current = transaction; base

Code First CTP4: Table with no primary key?

守給你的承諾、 提交于 2019-12-10 18:36:03
问题 With Entity Framework and Code First, is it possible to let it create and use a table with no primary keys? I can't get this setup to work: public class Report { public virtual int ReportId public virtual ICollection<ReportChanges> ReportChanges } public class ReportChanges { public virtual Report Report public virtual string EditorName public virtual DateTime Changed } Note that I've excluded assigning a primary key in ReportChanges. But with this setup I get: " Unable to infer a key for

EF CTP4 cascade delete on many to many relationship

穿精又带淫゛_ 提交于 2019-12-10 17:37:58
问题 I've created a many to many relationship using default conventions in EF CTP4 by defining an ICollection on both image and project entities. The mapping table is created as below: create table [dbo].[Images_Project] ( [Images_Id] [uniqueidentifier] not null, [Project_Id] [uniqueidentifier] not null, primary key ([Images_Id])); Unfortunately when I delete a project it is not cascading deletes to the image mapping table. I would expect EF to generate a key on both the Imanges_Id and Project_Id

Entity Framework persisting child collection sort order

牧云@^-^@ 提交于 2019-12-07 13:34:21
问题 In NHibernate I can map a collection as a List to persist the order of the collection to the database. I'm using EF Code First (CTP4). How can I persist the sort order of a child collection (IList) without exposing the relationship in my domain model? 来源: https://stackoverflow.com/questions/4327281/entity-framework-persisting-child-collection-sort-order

Entity Framework Code First CTP4 Default Column Values?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 17:39:12
问题 I have been looking into Code First with Entity Framework CTP4 and you can use the ModelBuilder to build up your table columns. Is there a way to set the default value for a column in the database using the ModelBuilder or some other mechanism? Thank You! 回答1: Couldn't find a way to add default value other than manualy edit via text editor / application This is a bug in the Entity Framework... 回答2: I am using the constructor to set the default values. Never failed me public class Activity {

Entity Framework Code First CTP4 Default Column Values?

人盡茶涼 提交于 2019-12-04 01:01:46
I have been looking into Code First with Entity Framework CTP4 and you can use the ModelBuilder to build up your table columns. Is there a way to set the default value for a column in the database using the ModelBuilder or some other mechanism? Thank You! Couldn't find a way to add default value other than manualy edit via text editor / application This is a bug in the Entity Framework... I am using the constructor to set the default values. Never failed me public class Activity { [Required] public DateTime AddedDate { get; set; } public Activity() { AddedDate = DateTime.Now; } } In the code

Entity Framework CTP 4. “Cannot insert the value NULL into column” - Even though there is no NULL value

走远了吗. 提交于 2019-11-27 19:35:24
Im using EF CTP 4. I have a simple console app (for testing purposes) that is using EF to insert some data into a SQL database. I have come to a problem where by upon inserting the item using(var context = GetContext()) { BOB b = new BOB(); b.Id = 1; context.Bobs.Add(b); context.SaveChanges(); } It throws the error: {"Cannot insert the value NULL into column 'Id', table 'TestDB.dbo.BOB'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."} The Table just has 1 field of Id int NOT NULL which is the primary key and is not an auto incremented Id. On the creation of

Entity Framework CTP 4 - Code First Custom Database Initializer

佐手、 提交于 2019-11-27 00:06:41
I would like to implement a custom database initialization strategy so that I can generate the database schema and apply it to an EXISTING EMPTY SQL database using a supplied User ID and Password. Unfortunately the built-in strategies don’t provide what I’m looking for: // The default strategy creates the DB only if it doesn't exist - but it does // exist so this does nothing Database.SetInitializer(new CreateDatabaseOnlyIfNotExists<DataContext>()); // Drops and re-creates the database but then this breaks my security mapping and // only works if using a “Trusted" connection Database

Entity Framework CTP 4. “Cannot insert the value NULL into column” - Even though there is no NULL value

拥有回忆 提交于 2019-11-26 19:55:27
问题 Im using EF CTP 4. I have a simple console app (for testing purposes) that is using EF to insert some data into a SQL database. I have come to a problem where by upon inserting the item using(var context = GetContext()) { BOB b = new BOB(); b.Id = 1; context.Bobs.Add(b); context.SaveChanges(); } It throws the error: {"Cannot insert the value NULL into column 'Id', table 'TestDB.dbo.BOB'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."} The Table just has 1