Hi All!

I've tried to use enum fields in my domain model. The documentation says, that it is allowed and supported.

(Modeling domains page: 1. The following field types are supported: sbyte, byte, short, ushort, int, uint, long, ulong; single, double, decimal; bool; string, char; DateTime, TimeSpan; Guid; enum; byte[]; Key; Descendants of Structure; Descendants of Entity; EntitySet<t>)

But Domain.Build(...) method throws an exception: "Literal type 'Model.EEntityLifeState' is not supported."

To be more precise... DO4 builds the domain without any exception when using in-memory provider, but throws the exception when using sqlexpress provider.

Part of my model:

[Serializable]
public class MyEntity : BaseBusinessEntity
{
    [Field(Nullable=false, DefaultValue=EEntityLifeState.Live)]
    public EEntityLifeState LifeState { get; set; }
}

[Serializable]
public enum EEntityLifeState
{
    Live, Deleted
}

}

Please someone make it clear, when and how can be used enums in the model, and when not!

Thanks!

Hi Peter and Alex!

you are right, the problem is with DefaultValue. I've commented out the DefaultValue, and the exception has gone away... :)

Alex, the stack trace: In the public available source code (on google code) I've checked the Xtensive.Sql.SqlValidator.EnsureLiteralTypeIsSupported(Type type) method, and it throws the exception, the code is fairly simple and self-explaining. :)

System.InvalidOperationException was unhandled Message=Literal type 'Model.EEntityLifeState' is not supported. Source=Xtensive.Sql
StackTrace: at Xtensive.Sql.SqlValidator.EnsureLiteralTypeIsSupported(Type type) at Xtensive.Sql.SqlDml.Literal(Object value) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.GetDefaultValueExpression(ColumnInfo columnInfo) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.CreateColumn(ColumnInfo columnInfo, Table table) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.CreateTable(TableInfo tableInfo) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitCreateTableAction(CreateNodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitCreateAction(CreateNodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.VisitAction(NodeAction action) at Xtensive.Storage.Providers.Sql.SqlActionTranslator.Translate() at Xtensive.Storage.Providers.Sql.SchemaUpgradeHandler.UpgradeSchema(ActionSequence upgradeActions, StorageInfo sourceSchema, StorageInfo targetSchema) at Xtensive.Storage.Building.Builders.DomainBuilder.SynchronizeSchema(SchemaUpgradeMode schemaUpgradeMode) at Xtensive.Storage.Building.Builders.DomainBuilder.BuildDomain(DomainConfiguration configuration, DomainBuilderConfiguration builderConfiguration) at Xtensive.Storage.Upgrade.UpgradingDomainBuilder.BuildStageDomain(UpgradeStage stage) at Xtensive.Storage.Upgrade.UpgradingDomainBuilder.Build(DomainConfiguration configuration) at Xtensive.Storage.Domain.Build(DomainConfiguration configuration) at TestProject1.Program.Main(String[] args) in C:\workspace\do4_playground\HousesETC\TestProject1\Program.cs:line 21 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

asked Nov 24 '10 at 19:37

tao99's gravatar image

tao99
27114

edited Nov 25 '10 at 08:16

Yep, likely, that's a correct answer.

I'd also recommend you to explicitly specify values for enum members (that might simplify future upgrades).

(Nov 25 '10 at 05:17) Alex Yakunin Alex%20Yakunin's gravatar image

P.S. Please publish stack traces.

(Nov 25 '10 at 05:18) Alex Yakunin Alex%20Yakunin's gravatar image

Moved my response to answer, please mark it as Accepted.

(Nov 25 '10 at 07:46) Peter Šulek Peter%20%C5%A0ulek's gravatar image

Thanks for the answer!

(Nov 25 '10 at 08:26) tao99 tao99's gravatar image

One Answer:

I think its bug in DefaultValue attribute. Because i am using enums in my datamodel with success. Try to remove DefaultValue attribute to test if it works.

answered Nov 25 '10 at 07:44

Peter%20%C5%A0ulek's gravatar image

Peter Šulek
492313236

edited Nov 25 '10 at 07:45

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