I've recently been playing around with fluent nhibernate & more specifically persistence specification testing.
However, I keep running into a sql lite error while running a relatively simple test with nunit when building the schema for the test on this line: (SessionSource.BuildSchema(Session)).
System.Data.SQLite.SQLiteException : SQLite error near "/": syntax error
Seeking some some guidance on what I am doing wrong as I'm relatively new to fluent. Is there an easier way to troubleshoot this error message?
public class Contact
{
public int Id { get; protected set; }
// some other properties
public IList<Note> Notes { get; set; }
}
public ContactMapping()
{
Not.LazyLoad();
Id(m => m.Id).GeneratedBy.Identity();
HasMany(x => x.Notes).KeyColumns.Add("ContactId");
}
public class Note
{
public int Id { get; protected set; }
public Contact Contact { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
public NoteMapping()
{
Not.LazyLoad();
Id(m => m.Id).GeneratedBy.Identity();
Map(m => m.Title).Not.Nullable().Length(250);
Map(m => m.Description).Not.Nullable().Length(2500);
References(x => x.Contact).Column("ContactId").Cascade.All();
}
Config:
public void SetupContext()
{
var cfg = Fluently.Configure()
.Database(SQLiteConfiguration.Standard
.ShowSql()
.InMemory
);
SessionSource = new SessionSource(cfg.BuildConfiguration()
.Properties, PersistenceModel());
Session = SessionSource.CreateSession();
SessionSource.BuildSchema(Session);
}
private static PersistenceModel PersistenceModel()
{
var model = new PersistenceModel();
model.AddMappingsFromAssembly(typeof(Contact).Assembly);
return model;
}
And finally the persistence test:
new PersistenceSpecification<Contact>(Session)
.CheckProperty(c => c.Id, 1)
.CheckProperty(c => c.First, "Coding")
.CheckProperty(c => c.Last, "Quiz")
.CheckProperty(c => c.Email, "[email protected]")
.CheckReference(c => c.Notes, new Note { Title = "Title", Description = "Description" })
.VerifyTheMappings();
You should be using CheckList
in the PersistanceSpecification
class instead of CheckReference
in the above code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With