1
所以我一直在爲此掙扎了大約半天吧.. 我來eclipselink和java,對於一個項目我正在做一些代碼與NHibernate和C#。 關於通過nhibernate上的代碼映射的不幸的文檔是我猜想的缺乏。我無法找到我得到了錯誤的任何資源..NHibernate映射的代碼,沒有persister爲:
出於測試目的,我用Northwind數據庫的工作,所以我創建了一個一流的客戶
public class Customer{
public virtual string CustomerID { get; set; }
public virtual string CompanyName { get; set; }
public virtual string ContactName { get; set; }
public virtual string ContactTitle { get; set; }
public virtual string Address { get; set; }
public virtual string City { get; set; }
public virtual string Region { get; set; }
public virtual string PostalCode { get; set; }
public virtual string Country { get; set; }
public virtual string Phone { get; set; }
public virtual string Fax { get; set; }
}
另外一個映射類:
public class CustomerMap: ClassMapping<Customer>
{
public CustomerMap() {
Schema("dbo");
Lazy(true);
Id(x => x.CustomerID, map => map.Generator(Generators.Assigned));
Property(x => x.CompanyName, map => map.NotNullable(true));
Property(x => x.ContactName);
Property(x => x.ContactTitle);
Property(x => x.Address);
Property(x => x.City);
Property(x => x.Region);
Property(x => x.PostalCode);
Property(x => x.Country);
Property(x => x.Phone);
Property(x => x.Fax);
}
}
但後來我得到的不留存錯誤
ModelMapper mm = new ModelMapper();
mm.AddMapping<CustomerMap>();
HbmMapping hbmm = mm.CompileMappingForAllExplicitlyAddedEntities();
XmlSerializer xml = new XmlSerializer(hbmm.GetType());
xml.Serialize(Console.Out, hbmm);
這是TH的XML上述E碼生成
<?xml version="1.0" encoding="Windows-1252"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="NHibernate.Classes.Domain" assembly="NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns="urn:nhibernate-mapping-2.2">
<class name="Customer" schema="dbo">
<id name="CustomerID" type="String">
<generator class="assigned" />
</id>
<property name="CompanyName" not-null="true" />
<property name="ContactName" />
<property name="ContactTitle" />
<property name="Address" />
<property name="City" />
<property name="Region" />
<property name="PostalCode" />
<property name="Country" />
<property name="Phone" />
<property name="Fax" />
</class>
</hibernate-mapping>
由於我與地圖通過代碼的東西的工作,我不想創建這個XML自己,所以我不知道什麼我可能是做錯了。我搜遍了谷歌。