我连接到传统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