Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If all your entities inherit from ReferenceEntity, wouldn't you want to create the unique constraint for the <code>Name</code> property on all the entities that are mapped?</p> <p>But if you want to filter by entity base class, you can do it. Use a convention to add the unique constraint to your mappings:</p> <pre><code>public class NameConvention : IPropertyConvention { public void Apply(IPropertyInstance instance) { // Check the entity base class type if (instance.EntityType.BaseType.Name == "ReferenceEntity") { // Only add constraint to the .Name property if (instance.Name == "Name") { instance.Unique(); } } } } </code></pre> <p>To get the convention (and all other conventions in the assembly) picked up by FNH, just add this line the <code>AutoMap</code> setup you have above:</p> <pre><code>.Conventions.AddFromAssemblyOf&lt;NameConvention&gt;() </code></pre> <hr> <p>Alex, </p> <p>No the answer doesn't change. Here is an example, using the convention above.</p> <pre><code>public abstract class ReferenceEntity { public virtual int Id { get; protected set; } public virtual string Name { get; set; } } public class User : ReferenceEntity { public virtual string Email { get; set; } } public class Item : ReferenceEntity { public virtual string Description { get; set; } } </code></pre> <p>This creates sql of:</p> <pre><code>create table Users ( Id INTEGER not null, Email TEXT not null, Name TEXT not null unique, primary key (Id) ) create table Items ( Id INTEGER not null, Description TEXT, Name TEXT not null unique, primary key (Id) ) </code></pre> <p>As long as these are separate entities, it will create a unique constraint on the .Name property for each entity. </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.
 

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