Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will try to explain it step by step, using the following Entity</p> <pre><code>public class Account { public int AccountId1 { get; set; } public int AccountId2 { get; set; } public string Description { get; set; } } </code></pre> <ol> <li><p>Create a class derived from the <code>EntityTypeConfiguaration&lt;TEntity&gt;</code> Object to override the conventions</p> <pre><code>class AccountEntityTypeConfiguration : EntityTypeConfiguration&lt;Account&gt; { public AccountEntityTypeConfiguration() { // The Key // The description of the HasKey Method says // A lambda expression representing the property to be used as the primary key. // If the primary key is made up of multiple properties then specify an anonymous type including the properties. // Example C#: k =&gt; new { k.Id1, k.Id2 } // Example VB: Function(k) New From { k.Id1, k.Id2 } this.HasKey(k =&gt; new { k.AccountId1, k.AccountId2 } ); // The Key // Maybe the key properties are not sequenced and you want to override the conventions this.Property(p =&gt; p.AccountId1).HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None); this.Property(p =&gt; p.AccountId2).HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None); this.Property(p =&gt; p.Description).IsRequired(); // This property will be required this.ToTable("Account"); // Map the entity to the table Account on the database } } </code></pre></li> <li><p>When create the class derived from the <code>DbContext</code> Object, override <code>OnModelCreating</code> Method and add a new <code>AccountEntityTypeConfiguration</code> object to the Configurations of the model Builder.</p> <pre><code>public class MyModelAccount : DbContext { public DbSet&lt;Account&gt; Accounts { get; set;} protected override void OnModelCreating(DbModelBuilder modelBuilder) { // Add a new AccountEntityTypeConfiguration object to the configuration of the model, that will be applied once the model is created. modelBuilder.Configurations.Add(new AccountEntityTypeConfiguration()); } } </code></pre></li> </ol> <p>Hope it helps you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload