ef-code-first

WPF and entity Framework code first

北慕城南 提交于 2019-12-10 09:56:38
问题 I would like to implement a simple WPF with a datagrid and a save button. when I click save button it will accept changes (row edit,cell edit, new row, delete etc) I tried RowEditHandler and CollectionChange event using observable collections. But I couldnt get a soluton. Can anyone please show me a simple way. Using dataset (xsd), I was able to achive that simpy by sending datacontext of grid to dataset and using update function. thanks for help 回答1: The ADO.NET team blog has an example how

How to associate one table to many parents using EF Code First

坚强是说给别人听的谎言 提交于 2019-12-10 09:42:09
问题 I am building a domain model that requires several tables to be able to be references by more than one possible parent table. Something like you might have a table to store notes or files and those notes and/or files can be associated with different parent entities. Not that the same "file" or "note" can be associate with multiple owners, but that of 10 rows in a "files" table, 3 of them might be owned by rows from a "Customer" table, 3 of them might be owned by rows from an "Orders" table,

Entity Framework DbSet.Find throws exception

与世无争的帅哥 提交于 2019-12-10 09:35:28
问题 I'm following a very basic example of code-first Entity Framework (version 4.1) in ASP.NET MVC 4 (using the EBuy example in O'Reilly's Programming ASP.NET MVC 4). I've searched for solutions to this and so far have drawn blank. The basic problem is this code in my controller: public ActionResult Details(long id) { using (var db = new EbuyDataContext()) { var rep = db.Auctions; var auction = rep.Find(id); return View(auction); } } throws an ArgumentNullException Value cannot be null. Parameter

Npgsql can't find NpgsqlException when doing Migrations

a 夏天 提交于 2019-12-10 09:28:28
问题 When I do an update-database and an error happens at the database I get: System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Npgsql.NpgsqlException,Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'. Its trying to tell me about an error but I presume it can't find the exception type its trying to wrap it in so I'm left guessing at my mistake. I'm using version 2.2.5.0 Npgsql.EntityFramework which is currently the latest version. 回答1:

How do I get the Entity Framework to initialise collections on my newly-created entities?

半腔热情 提交于 2019-12-10 02:56:34
问题 I'm trying to seed my database with some test data with an IDatabaseIntialiser like this: protected override void Seed(BlogDataContext context) { // <snip> var post = context.Posts.Create(); post.Title = "My Life On Twitter"; // <snip properties> // Set tags post.Tags.Add(aspnetTag); // NullRefException post.Tags.Add(razorTag); Post entity looks like this: public class Post { // ... public virtual ICollection<Tag> Tags { get; set; } Full entities at Bitbucket: Post and Tag. All code is at

Changing primary key data type in Production DB

▼魔方 西西 提交于 2019-12-09 23:43:24
问题 I am using EF code-first. I need to change the datatype of primary key of one table in our production database. public class Course { [Key] public Guid Id {get; set;} //This needs to be changed to int public string Name {get;set;} public virtual ICollection<Group> Groups {get;set;} } public class Group { [Key] public Guid Id {get; set;} public string Name {get;set;} public virtual ICollection<Course> Courses{get;set;} } As the above is a Many-Many relationship, EF has created a join table

Entity with many-to-many relationship creation fails after upgrading to RC

最后都变了- 提交于 2019-12-09 20:57:03
问题 I've got a project with 3 simple tables, a couple of POCO classes, and a DBContext created with code, no edml file. The following code setup used to work with the beta of Entity Framework code-first, I've edited the DbContext code since the ModelBuilder changed from the beta to RC Tables (simple tables many-to-many table has fields declared as foreign keys with cascade deletion): CREATE TABLE [dbo].[Bookings]( [ID] [int] IDENTITY(1,1) NOT NULL, [StartDate] [datetime] NOT NULL, [EndDate]

EF Code First Migration unwanted column IdentityRole_Id

梦想的初衷 提交于 2019-12-09 20:04:37
问题 I'm using EF 6.1.1 When i use code-first migration on my DB, it adds two unwanted columns to the AspNetUserRoles table: IdentityRole_Id, IdentityUser_Id I've seen this RemoveFromRole cannot work as expected, but didnt help me. how do i get rid of them ?? this is my OnModelCreating protected override void OnModelCreating(DbModelBuilder modelBuilder) { if (modelBuilder == null) { throw new ArgumentNullException("modelBuilder"); } // Keep this: modelBuilder.Entity<IdentityUser>().ToTable(

Mapping to already existing database table

ぃ、小莉子 提交于 2019-12-09 19:14:37
问题 I am using Entity Framework 4.1 code first to connect to an already existing database. The table that I am using first is called Bank . I also have a Bank class as my domain model. This is how I mapped my class and table: public class HbfContext : DbContext { public DbSet<Bank> Banks { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Bank>().ToTable("Bank"); } } My Bank table: BankID INT BankName VARCHAR(50) My Bank class looks like this:

Mapping for self referencing entity in EF Code First

我的未来我决定 提交于 2019-12-09 18:15:47
问题 In my database I have a table Category, with columns Id, CategoryName, ParentCategoryId, where ParentCategoryId has a constraint on Category.Id. I'm using entity framework code first, where the entity looks like: public class Category { public long Id { get; private set; } public string CategoryName { get; private set; } public long? ParentCategoryId { get; private set; } public Category ParentCategory { get; private set; } public virtual ICollection<Category> SubCategories { get; private set