ef code first - Asp.Net MVC Codefirst Model Relation to the Same Model -
I have a model and I want to put the same model to an additional area which can be filled with the form For Ireland:. Categories and sub categories
In my example, visitors can add a file type but the file type can be selected if another file type is being done, but I can not work on it. Below you can see my model You just need to add a You can also use the fluent API to achieve this goal: Public class HR file type {{Key} Public Ent ID {Receive; Set; } [Display (name = "Dojo Edu")] Public at name {get; Set; } Public int? HrFileTypeId {Receive; Set; } Public Virtual HrFileType HrFileType2 {get; Set; }}
to foreignKeyAttribute As follows:
public class HrFileType {[Key] public int id {get; Set; } [Display (name = "Dojo Edu")] Public at name {get; Set; } Public int? HrFileTypeId {Receive; Set; } [Foreign key ("HR filetype ID")] Public virtual HR file type HR file type 2 {Received; Set; }}
public class HrFileType {[Key] Public Integer ID {Find; Set; } [Display (name = "Dojo Edu")] Public at name {get; Set; } Public int? HrFileTypeId {Receive; Set; } Public Virtual HrFileType HrFileType2 {get; Set; }} Public category YourDbContext: DbContext {public DbSet & lt; HrFileType & gt; HrFileTypes {get; Set; } Protected Override Zero OnModelCreating (DbModelBuilder modelBuilder) {// modelBuilder.Entity & LT; HrFileType & gt; () .HasOptional (c = & gt; c.HrFileType2) .WithMany () .HasForeignKey (c = & gt; c.HrFileTypeId); }}
Comments
Post a Comment