2009-11-15 71 views
7

我有我的SQL Server數據庫,需要加以VARBINARY(最大)一個VARBINARY場。我用NHibernate創建我的數據庫,並使用Fluent Nhibernate作爲我的映射。功能NHibernate,VARBINARY(max)和SQLite的

我也使用SQLite爲我的單元測試,我使用相同的映射在內存中創建數據庫之前,我只需要改變配置。

我碰到下面的問題。

我創造了這個擴展方法:

public static IProperty WithMaxVarBinaryLength(this IProperty propertyMap) 
{ 
    return propertyMap.CustomSqlTypeIs("varbinary(max)"); 
} 

它工作在我的網站很好,數據庫用VARBINARY(最大值)字段創建的,但是當我運行我的單元測試中,我得到下面的異常

public static IProperty WithMaxLength(this IProperty propertyMap) 
{ 
    return propertyMap.WithLengthOf(1000); 
} 
System.Data.SQLite.SQLiteException: SQLite error near "max": syntax error 

然後我在計算器另一個問題,我們可以這樣做是爲了創建一個VARBINARY(最大值)發現

但我得到這個異常:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Content is not a string. at FluentNHibernate.Mapping.PropertyMap.WithLengthOf(Int32 length) in d:\Builds\FluentNH\src\FluentNHibernate\Mapping\PropertyMap.cs:line 166 

對於我出想法的那一刻,我不想手動創建所有的數據庫腳本,我想繼續使用SQLite,讓我的單元測試。

感謝您的幫助。

順便說一句,這是我的完整映射,請注意,我用我的推廣方法。

public class AttachmentFileMap : ClassMap<AttachmentFile> 
{ 
    public AttachmentFileMap() 
    { 
     WithTable("AttachmentFiles"); 

     Id(x => x.Id).GeneratedBy.Identity(); 
     Map(x => x.Content).WithMaxVarBinaryLength(); 
     Map(x => x.ContentType); 
     Map(x => x.FileName); 
     Map(x => x.ContentLength); 
    } 
} 

內容是一個byte []

查爾斯

回答

4

最後我發現功能NHibernate的新版本解決了此問題,現在可以字節的屬性後,使用。長度() []類型,它完美的作品。

我也不得不更新我的NHibernate的DLL和修改一些代碼在我的映射類,因爲功能NHibernate的新版本已更名爲新版本的一些方法。