entity-framework

Entity Framework 5 stopped running T4 templates files on save

北城余情 提交于 2020-01-13 12:08:31
问题 At work we just upgraded to Entity Framework 5. Our EDMX file now has a couple other nodes beneath it: EntityContainer.Context.tt which contains the generated DbContext object and EntityContainer.tt which contains the entities themselves. For a short period, adding an entity in EF was automatically regenerating the tt (T4 Templates) when we would save the EDMX file. Now all of a sudden we have to right-click the T4 templates and select "Run Custom Tool" to get them to regenerate the .cs files

Entity Framework 5 stopped running T4 templates files on save

亡梦爱人 提交于 2020-01-13 12:08:13
问题 At work we just upgraded to Entity Framework 5. Our EDMX file now has a couple other nodes beneath it: EntityContainer.Context.tt which contains the generated DbContext object and EntityContainer.tt which contains the entities themselves. For a short period, adding an entity in EF was automatically regenerating the tt (T4 Templates) when we would save the EDMX file. Now all of a sudden we have to right-click the T4 templates and select "Run Custom Tool" to get them to regenerate the .cs files

EF5: How to alter the default Delete function to implement my own

纵饮孤独 提交于 2020-01-13 11:34:08
问题 Well, here is my situation: We have tables that we dont want ever to delete the data. There is a column which is called isDeleted that is supposed to be updated instead instead of deleting it. I want to develop the accompanying web app with EF5 but i have a problem there. How do i implement that restriction? I could use stored procedures to delete and select but i was hoping for a way to use the standard functions in EF, just changing how they work. Which way is less arduous and what options

Prevent NULL checks in LINQ to Entity Joins

不打扰是莪最后的温柔 提交于 2020-01-13 11:33:40
问题 We have a table called Student . That table has a field called Homeroom , where the value is a room number of the student's homeroom. The value can be null. We have a second table called Staff . That table also has a field called Homeroom to indicate which homeroom the teacher is assigned to. The value can be null. But when the student's Homeroom is null, a Staff record should not be returned. We used to take advantage of the fact that checking two null fields for equality always returns

Prevent NULL checks in LINQ to Entity Joins

北城余情 提交于 2020-01-13 11:33:06
问题 We have a table called Student . That table has a field called Homeroom , where the value is a room number of the student's homeroom. The value can be null. We have a second table called Staff . That table also has a field called Homeroom to indicate which homeroom the teacher is assigned to. The value can be null. But when the student's Homeroom is null, a Staff record should not be returned. We used to take advantage of the fact that checking two null fields for equality always returns

Apply all IEntityTypeConfiguration derived classes in EF Core

廉价感情. 提交于 2020-01-13 11:07:34
问题 Does anyone know of a way or have an implementation to apply ALL classes that derive from IEntityTypeConfiguration<> to the DbContext at runtime? There doesn't seem to be anything built in and loading each one manually via: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new Table1Config()) modelBuilder.ApplyConfiguration(new Table2Config()) ... modelBuilder.ApplyConfiguration(new TableNConfig()) } is going to prove rather tedious for a

Apply all IEntityTypeConfiguration derived classes in EF Core

瘦欲@ 提交于 2020-01-13 11:07:32
问题 Does anyone know of a way or have an implementation to apply ALL classes that derive from IEntityTypeConfiguration<> to the DbContext at runtime? There doesn't seem to be anything built in and loading each one manually via: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new Table1Config()) modelBuilder.ApplyConfiguration(new Table2Config()) ... modelBuilder.ApplyConfiguration(new TableNConfig()) } is going to prove rather tedious for a

EF Composite key fluent API

≡放荡痞女 提交于 2020-01-13 10:50:07
问题 I am trying to map a composite key for an entity. public class Customer { public int CustomerId { get; set; } public virtual List<CustomerImage> CustomerImages { get; set; } } And its Map: public class CustomerMap : EntityTypeConfiguration<Customer> { public CustomerMap() { HasKey(t => t.CustomerId); ToTable(DbConstants.k_CustomersImageTable); } } An Image: public class Image { public int ImageId { get; set; } } And its map: public class ImageMap : EntityTypeConfiguration<Image> { public

EF get list of records in runtime from Type

久未见 提交于 2020-01-13 10:36:12
问题 Purpose: I need to loop all records like: var records = db.Set<UserAccount>().ToList(); Then loop foreach (var record in records) { // do something with the record } But it has to not type specific in runtime, as I am to loop through types and therefor do not know example "UserAccount". Only the Type/TypeOf? In the bottom of this description I have a method loopAllEntities that I cannot find a way to work I have created an DbContext with some entities. public class MyEntities : DbContext {

Entity Framework Seeding with Identity (Microsoft.Owin.Security) user

房东的猫 提交于 2020-01-13 10:30:08
问题 I have a class that seed the database which add 2 users with roles and custom fields. The problem I have is that it save the data in [dbo].[AspNetUsers] instead of [dbo].[IdentityUsers]. Both tables are created. When seeded, the data go into AspNetUser. When I launch the web site, and register a new user, the data go into IdentityUser. Here is the Migration class : internal sealed class Configuration : DbMigrationsConfiguration<DatabaseContext> { public Configuration() {