Jes*_*sse 3 c# nhibernate foreign-keys fluent-nhibernate
我最近一直在使用流利的nhibernate和更具体的持久性规范测试.
但是,在为此行构建测试模式时,我在运行相对简单的nunit测试时遇到了sql lite错误:(SessionSource.BuildSchema(Session)).
System.Data.SQLite.SQLiteException:"/"附近的SQLite错误:语法错误
寻求一些关于我做错的指导,因为我对流利相对较新.有没有更简单的方法来解决此错误消息?
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();
}
Run Code Online (Sandbox Code Playgroud)
配置:
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;
}
Run Code Online (Sandbox Code Playgroud)
最后是持久性测试:
new PersistenceSpecification<Contact>(Session)
.CheckProperty(c => c.Id, 1)
.CheckProperty(c => c.First, "Coding")
.CheckProperty(c => c.Last, "Quiz")
.CheckProperty(c => c.Email, "mail@test.com")
.CheckReference(c => c.Notes, new Note { Title = "Title", Description = "Description" })
.VerifyTheMappings();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2064 次 |
最近记录: |