ef-fluent-api

How to retrieve Entity Configuration from Fluent Api

落爺英雄遲暮 提交于 2019-12-05 02:41:09
Using Entity-Framework 6 I'm able to set up the configuration through Fluent Api like this: public class ApplicationUserConfiguration : EntityTypeConfiguration<ApplicationUser> { public ApplicationUserConfiguration() { this.HasKey(d => d.Id); this.Ignore(d => d.UserId); } } Source from this question Using the attribute approach I'm able to know what's the property roles by reflection, but I wonder how can I retrieve these configurations, like Key for example, with Fluent Api approach? There's no public property from the EntityTypeConfiguration<> class. Is that possible to get the Key and

Mapping to already existing database table

南笙酒味 提交于 2019-12-04 15:22:52
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: public class Bank { public int Id { get; set; } public string Name { get; set; } public bool IsActive {

Multiple indexes possible using HasColumnAnnotation?

自闭症网瘾萝莉.ら 提交于 2019-12-04 09:03:07
问题 It looks like in Entity Framework 6.1 they added the ability to create table indexes via the new HasColumnAnnotation method. I created a few helper extensions to speed up the process: public static class MappingExtensions { public static StringPropertyConfiguration HasIndex(this StringPropertyConfiguration config, bool isUnique = false) { return config.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute() { IsUnique = isUnique })); } public static StringPropertyConfiguration

What is Entity Framework fluent api?

﹥>﹥吖頭↗ 提交于 2019-12-04 07:29:31
问题 I keep hearing about the Entity Framework fluent-api but I am struggling to find a good reference on this. What is it? We use the entity framework and the modeling tool provided. Is that all that is? Or is it something different? Similarly, if it's not too broad a question, what is POCO? I know it stands for Plain Old CLR Objects, but what does that mean to me as somebody who uses EF already with the designer model tool? If that question is too vague then please ignore it. I'm just learning

Column Extent1.Id does not exist in Mono with Entity Framework 6 and PostgreSQL

风流意气都作罢 提交于 2019-12-04 05:14:54
问题 I am trying to map to a PostgreSQL database with Entity Framework using the packages Npsql and Npsql.EntityFramework. I have a database with the following table: CREATE TABLE IF NOT EXISTS Crops ( Id INT PRIMARY KEY NOT NULL, Name TEXT NOT NULL, SowingMonths INT ); The Crop model looks as follows: public class Crop { public int Id { get; set; } public string Name { get; set; } public Month SowingMonths { get; set;} //Month is an enum } In the database context I map the schema to public since

aspnet core entity framework 7 self referencing “job” 1 to many table

空扰寡人 提交于 2019-12-04 05:12:52
问题 I have a "Job" table that contains jobs. The fact is Jobs are not always done in one go.. you can have a job that has many visits. I intended to represent that as another job but linked back to the original job via self referencing linkId. I am having trouble representing this using the fluent API. Its a one to many relationship.. one job might have many visits and thus a number of linkId's point back to the orginal job. The link Id would back to the orginal job Id. Its also optional since

EntityFramework Code First FluentAPI DefaultValue in EF6.X

做~自己de王妃 提交于 2019-12-03 23:29:25
How can I set the default value using EntityFramework Code First FluentAPI for bool property? Something like: Property(l => l.PropertyFlag).HasColumnType("bit").DefaultValue(1); Good news, code first now supports this. In the "Up()" method of the generated migration, specify a default with the following syntax: AddColumn("[table name]", "[column name]", c => c.Boolean(nullable: false, defaultValue: false)); MSDN for "AddColumn" method I'm not sure about a fluent way, but you can simply set the property in a parameterless constructor... public class MyTable { public MyTable() { CanSetDefault =

One-to-One relationships in Entity Framework 7 Code First

纵然是瞬间 提交于 2019-12-03 06:51:53
How to configure One-to-One or ZeroOrOne-to-One relationships in Entity Framework 7 Code First using Data Annotations or Fluent Api? You can define OneToOne relationship using Fluent API in Entity Framework 7 as below class MyContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<BlogImage> BlogImages { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>() .HasOne(p => p.BlogImage) .WithOne(i => i.Blog) .HasForeignKey<BlogImage>(b => b.BlogForeignKey); } } public class Blog { public int BlogId { get; set; } public string

Possible to set column ordering in Entity Framework

别等时光非礼了梦想. 提交于 2019-12-03 03:18:45
Is there any possible configuration to set database column ordering in entity framework code first approach..? All of my entity set should have some common fields for keeping recordinfo public DateTime CreatedAt { get; set; } public int CreatedBy { get; set; } public DateTime ModifiedAt { get; set; } public int ModifiedBy { get; set; } public bool IsDeleted { get; set; } I want to keep this fields at the end of the table. Is there any possible EF configuration that i can use to config this rather than keeping this fields at the end of my model class. I'm assuming you are using Entity Framework

Entity Framework Fluent API relationship mapping HasRequired().WithRequired() not behaving correctly without Map()

假装没事ソ 提交于 2019-12-02 21:15:22
问题 Blog Model using System.Collections.Generic; namespace DataLayer { public class Blog { public int BlogKey { get; set; } public string Title { get; set; } public string BloggerName { get; set; } public virtual Post Post { get; set; } } } Post Model using System; using System.Collections.Generic; namespace DataLayer { public class Post { public int PostKey { get; set; } public string Title { get; set; } public DateTime? DateCreated { get; set; } public string Content { get; set; } public