It seems that there is bug in DefaultValue for Enum in Structures when adding new fields.

Initially we have:

[HierarchyRoot]
[Serializable]
public class Book : Entity
{
    [Field, Key]
    public int Id { get; private set; }

    [Field]
    public string Title { get; set; }
}

Now creating:

new Book() { Title = "Alfabet" };
new Book() { Title = "Second" };
new Book() { Title = "Blue" };

After that adding structure BookSettings to class Book:

[Serializable]
public class BookSettings: Structure
{
    [Field(DefaultValue = BookSize.Octavo)]
    public BookSize Size { get; set; }

    [Field(DefaultValue = 55)]
    public int Pages { get; set; }

}

public enum BookSize
{
    Folio = 0,
    Quarto = 1,
    Octavo = 2
}

[HierarchyRoot]
[Serializable]
public class Book : Entity
{
    [Field, Key]
    public int Id { get; private set; }

    [Field]
    public string Title { get; set; }

    [Field]
    public BookSettings BookSettings { get; set; }

}

Trying to perform and exception:

[InvalidOperationException: Literal type 'DomainModel.BookSize' is not supported.]
Xtensive.Sql.SqlValidator.EnsureLiteralTypeIsSupported(Type type) +102
Xtensive.Sql.SqlDml.Literal(Object value) +80
Xtensive.Storage.Providers.Sql.SqlActionTranslator.GetDefaultValueExpression(ColumnInfo columnInfo) +75
Xtensive.Storage.Providers.Sql.SqlActionTranslator.CreateColumn(ColumnInfo columnInfo, Table table) +438
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitCreateColumnAction(CreateNodeAction createColumnAction) +196
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitCreateAction(CreateNodeAction action) +193
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +282
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +183
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +183
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +183
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +183
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +183
Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) +183
Xtensive.Storage.Providers.Sql.SqlActionTranslator.Translate() +877
Xtensive.Storage.Providers.Sql.SchemaUpgradeHandler.UpgradeSchema(ActionSequence upgradeActions, StorageInfo sourceSchema, StorageInfo targetSchema) +982
Xtensive.Orm.Building.Builders.DomainBuilder.SynchronizeSchema(SchemaUpgradeMode schemaUpgradeMode) +2240
Xtensive.Orm.Building.Builders.DomainBuilder.BuildDomain(DomainConfiguration configuration, DomainBuilderConfiguration builderConfiguration) +594
Xtensive.Orm.Upgrade.UpgradingDomainBuilder.BuildStageDomain(UpgradeStage stage) +406
Xtensive.Orm.Upgrade.UpgradingDomainBuilder.Build(DomainConfiguration configuration) +436
Xtensive.Orm.Domain.Build(DomainConfiguration configuration) +31

We found:

  • We get exception in case of adding Enum field to Structure with DefaultValue, but no matters, are there any records in database or not.

  • When adding int field - everyting is ok.

  • When adding Enum field to Entity (not Structure) everything is ok.

But there is one way to solve this: we can add Enum Field to Structure without DefaulValue. After that doing perform. And now we can add DefaultValue and it is successfully applied to the newly created entities.

asked Feb 09 '12 at 11:01

Ness's gravatar image

Ness
155232328

edited Feb 10 '12 at 02:01

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211


One Answer:

Ness,

Thanks a lot for the investigation you performed and for sharing the workaround with the community. Likely, the fix will be more or less trivial, so it can be expected in one of the future minor releases.

Good work!

answered Feb 10 '12 at 02:10

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA