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
27●1●1●4
Yep, likely, that's a correct answer.
I'd also recommend you to explicitly specify values for enum members (that might simplify future upgrades).
P.S. Please publish stack traces.
Moved my response to answer, please mark it as Accepted.
Thanks for the answer!