Skip to content

Property configuration

Roman Sinclair edited this page Apr 22, 2020 · 6 revisions

Like for entity, for property configuration you can use attributes or fluent configuration.

Configure property with fluent configuration

Fluent:

Entity<Customer>.Add()
        .ConfigureProperty(PropertyOf<Customer>.Configure(c => c.CompanyName))

And now you ready to configure a CompanyName property.


SQL column name

Attribute:

[Column("CompanyName")]
public string CompanyName { get; set; }

Fluent:

PropertyOf<Customer>.Configure(c => c.CompanyName).SetColumnName("CompanyName");

On delete

Attribute:

[OnDelete(DeleteOption.SetNull)]
public ICollection<Order> Orders { get; set; }

Fluent:

PropertyOf<Customer>.Configure(c => c.Orders).OnDelete(DeleteOption.CascadeDelete)

Primary key

Attribute:

[Key]
public string CustomerId { get; set; }

Fluent:

PropertyOf<Customer>.Configure(c => c.CustomerId).IsKey()

Display name

Attribute:

[Display(Name = "Company")]
public string CompanyName { get; set; }

Fluent:

PropertyOf<Customer>.Configure(c => c.CompanyName).SetDisplayName("Company")

Templates

Templates are automatically determined based on property type.

But you can change template. You can create own custom template and pass their name to Ilaro.Admin.

You can also override existing partial view, Attribute:

[Template(DisplayTemplate = Templates.Display.Html, EditorTemplate = Templates.Editor.Html)]
public string Address { get; set; }

Fluent:

PropertyOf<Customer>.Configure(c => c.CompanyName)
      .SetDisplayTemplate(Templates.Display.Html)
      .SetEditorTemplate(Templates.Editor.Html)

Image

Attribute:

Fluent:


Nullable and Required Properties

To make an attribute Nullable (not required), the underlying type has to be Nullable (notice the question mark after the type). Apparently, there's no way to make property Nullable using Fluent configuration. All properties that are not marked as Nullable are treated as Required in the View.

Attribute:

public DateTime? ArrivalDate { get; set; }