我連接到傳統sqlserver數據庫。其中一個表的列名稱爲「Primary」。由於這個原因,腳本失敗了。nhibernate連接到傳統數據庫
腳本由NHibernate的產生: SELECT locations0_.CustomerID如CustomerID1_,locations0_.LocationID如LocationID1_,locations0_.LocationID如LocationID2_0_,locations0_.Primary如Primary2_0_,locations0_.CustomerID如CustomerID2_0_ FROM dbo.tblLocation locations0_ WHERE locations0_。客戶ID =?
類別:
public class Location
{
public virtual int LocationID { get; set; }
public virtual Customer Customer { get; set; }
public virtual int? CustomerID { get; set; }
public virtual string LocationName { get; set; }
public virtual string Address1 { get; set; }
public virtual string Address2 { get; set; }
public virtual string Address3 { get; set; }
public virtual string City { get; set; }
public virtual string StateOrProvince { get; set; }
public virtual string PostalCode { get; set; }
public virtual datetime? LTimeStamp{ get;set; }
public virtual bool Primary { get; set; }
}
地圖: 公共類TblLocationMap:類映射 {
public TblLocationMap()
{
Table("tblLocation");
//LazyLoad();
Id(x => x.LocationID).GeneratedBy.Identity().Column("LocationID");
References(x => x.Customer).Column("CustomerID");
Map(x => x.LocationName).Column("LocationName").Length(50);
Map(x => x.Address1).Column("Address1").Length(200);
Map(x => x.Address2).Column("Address2").Length(200);
Map(x => x.Address3).Column("Address3").Length(200);
Map(x => x.City).Column("City").Length(100);
Map(x => x.StateOrProvince).Column("StateOrProvince").Length(100);
Map(x => x.PostalCode).Column("PostalCode").Length(20);
//Map(x => x.Primary).Column("Primary").Not.Nullable();
//Map(x => x.LTimestamp).Column("LTimestamp");
HasMany(x => x.Contacts).KeyColumn("LocationID");
}
SQL:
CREATE TABLE [DBO] [tblLocation] ( [LocationID ] [int] IDENTITY(1,1)NOT NULL, [CustomerID] [int] NULL, [LOCATIONNAME] nvarchar的NULL, [地址1] nvarchar的NULL, [地址2] nvarchar的NULL, [地址3] nvarchar的NULL, [市] nvarchar的NULL, [StateOrProvince] nvarchar的NULL, [POSTALCODE] nvarchar的NULL, [主] [比特] NOT NULL, [RecTimestamp] [時間戳] NULL, ( [LocationID] ASC )WITH(PAD_INDEX = OFF,STATISTICS_NORECOMPUTE = OFF,IGNORE_DUP_KEY = OFF,ALLOW_ROW_LOCKS = ON,ALLOW_PAGE_LOCKS = ON)ON [PRIMARY] )ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
GenericADOException: 無法初始化集合:[Domain.Locations#466] [SQL:SELECT locations0_.CustomerID爲CustomerID1_,locations0_.LocationID爲LocationID1_,locations0_.LocationID爲LocationID2_0_,locations0_.LocationName爲Location2_2_0_,locations0_。地址1作爲地址3_2_0_,地址0_地址2作爲地址4_2_0_,地址0_地址3作爲地址5_2_0_,地址0_。城市作爲城市2_0_,地點0_.StateOrProvince作爲StateOrP7_2_0_,地點0_.PostalCode作爲PostalCode2_0_,地點0_.Primary作爲Primary2_0_,地點0_.CustomerID作爲CustomerID2_0_從dbo.tblLocation locations0_ WHERE locations0_.CustomerID =?]
內部例外: {「關鍵字'Primary'附近的語法錯誤。」}
給我們提供更多信息:你會得到什麼錯誤? – madth3
添加映射,類和實際的數據庫表到這個職位,我們可以回答你的問題。 –
已更新。我從表中刪除了一些列。當nhibernate使用Primary列創建sql腳本時,它不起作用。但沒有它的作品。 – sunny