如何为FluentNHibernate映射添加int数组默认值

时间:2013-03-22 12:48:20

标签: c# mysql arrays fluent-nhibernate hibernate-mapping

最近,我在UserMap类中添加了一个新列,以添加一个int数组

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("user");
        LazyLoad();
        Id(x => x.Id).GeneratedBy.Identity().Column("Id");
        Map(x => x.DateCreated).Column("DateCreated").Not.Nullable();
        Map(x => x.Birthday).Column("Birthday").Nullable();
        Map(x => x.HideBirthday).Column("HideBirthday").Nullable();
        Map(x => x.Name).Column("Name").Not.Nullable();
        Map(x => x.Email).Column("Email").Not.Nullable();
        Map(x => x.PassWord).Column("Password").Not.Nullable();
        Map(x => x.NotificationCounter).Column("NotificationCounter").Nullable().Default("0");
        //EMAILPRIVACY = int[]
        Map(x => x.EmailPrivacy).Column("EmailPrivacy").Nullable();
    }
}

因此,我需要使用int数组向 EmailPrivacy 列添加默认值。

new int[] { 1, 2, 3, 4, 5, 6, 7 }

当我添加默认值时,我收到了错误:

Map(x => x.EmailPrivacy).Column("EmailPrivacy").Nullable().Default(new int[] { 1, 2, 3, 4, 5, 6, 7 }.ToString());

错误讯息:

Unknown column 'user0_.EmailPrivacy' in 'field list'

[MySqlException (0x80004005): Unknown column 'user0_.EmailPrivacy' in 'field list']
MySql.Data.MySqlClient.MySqlStream.ReadPacket() +383
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId) +116
MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId) +54
MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +142
MySql.Data.MySqlClient.MySqlDataReader.NextResult() +1249
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +2214
MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +12
NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +347
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) +364
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +425
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +213
NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) +386

如何添加此int []默认值?

提前感谢所有

0 个答案:

没有答案