我第一次使用nhibernate,但我想尽可能避免使用nhibernate fluent配置文件。我有一个项目设置,我正在尝试使用以下方法简单地查询一个地址对象
[TestMethod]
public void TestMethod1()
{
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.Is("[ConnectionStringHere")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<RedSand.Models.Data.Mapping.AddressMapping>());
var sessionFactory = cfg.BuildSessionFactory();
var session = sessionFactory.OpenSession();
session.Get<Address>(new Guid("A8B9BA39-425D-4AE6-A72E-00216ABC87C4"));
}
但是它在爆炸
Get<T>()
方法,该方法有一个错误,它抱怨没有持久器。我的地址分类如下。
public class Address
{
public Guid AddressId { get; set; }
public string AddressType { get; set; }
public string StreetAddress { get; set; }
public Guid CityId { get; set; }
public string PostalCode { get; set; }
public bool DefaultAddress { get; set; }
public bool TermAddress { get; set; }
public string SuiteNumber { get; set; }
public float Latitude { get; set; }
public float Longitude { get; set; }
public int Accuracy { get; set; }
}
public class AddressMapping : ClassMap<Address>
{
public AddressMapping()
{
Table("tblAddress");
Not.LazyLoad();
Id(a => a.AddressId).Column("AddressID").GeneratedBy.Guid();
Map(a => a.StreetAddress).Column("Address").Length(100);
Map(a => a.CityId).Column("CityID");
Map(a => a.PostalCode).Length(50);
Map(a => a.DefaultAddress);
Map(a => a.TermAddress).Default("0");
Map(a => a.SuiteNumber).Column("SuiteNo").Length(50);
Map(a => a.Latitude);
Map(a => a.Longitude);
Map(a => a.Accuracy);
}
}
我使用的是一个现有的数据库,所以请尝试忽略这个奇怪的表结构/命名。
我是不是错过了什么?你们中有人能看到一些能解释为什么他们抱怨一个不坚持的人吗?