Ich habe ein varbinary-Feld in meiner SQL Server-Datenbank, die Varbinary (max) sein muss. Ich erstelle meine Datenbank mit NHibernate und verwende Fluent Nhibernate für meine Mappings.Fluent NHibernate, varbinary (max) und SQLite
Ich verwende auch SQLite für meine Unit-Tests, ich benutze die gleichen Mappings Ich ändere nur die Konfiguration vor dem Erstellen der Datenbank im Speicher.
Ich bekomme das folgende Problem.
Ich habe diese Erweiterung Methode:
public static IProperty WithMaxVarBinaryLength(this IProperty propertyMap)
{
return propertyMap.CustomSqlTypeIs("varbinary(max)");
}
Es ist auf meiner Website gut funktioniert, wird die Datenbank mit einem varbinary (max) Feld erstellt, aber wenn ich meine Unit-Tests laufen bekomme ich die folgende Ausnahme
System.Data.SQLite.SQLiteException: SQLite error near "max": syntax error
Dann fand ich in einer anderen Frage auf Stackoverflow, dass wir dies tun können, eine varbinary (max) zu erstellen:
public static IProperty WithMaxLength(this IProperty propertyMap)
{
return propertyMap.WithLengthOf(1000);
}
Aber ich bekomme diese Ausnahme:
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
Für den Moment, als ich aus Idee bin, will ich nicht manuell alle Skripte meiner Datenbank erstellen haben, und ich möchte mit SQLite für meine Unit-Tests fortzusetzen.
Danke für die Hilfe.
Übrigens, hier ist meine vollständige Zuordnung, beachten Sie, dass ich meine Erweiterungsmethoden verwendet.
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);
}
}
Inhalt ist ein byte []
Charles