iam尝试通过流畅的Nhibernate映射查询外部数据库,但当NHibernate尝试重新创建本地数据库时,会引发There is already an object named
错误
这是外部数据库中存在的表:
CREATE TABLE [dbo].[TX01_Society] (
[IdSociety] INT NOT NULL,
[Society] NVARCHAR (50) NULL,
[Valid] BIT NULL,
PRIMARY KEY CLUSTERED ([IdSociety] ASC)
);
这是我在应用程序db中创建的视图:
CREATE VIEW [dbo].QX01_Society
AS SELECT
TX01_Societa.IdSociety AS Kint_QX01_IDSociety
, TX01_Societa.Society as nvc_QX01_Society
, TX01_Societa.Valid as bit_QX01_Valid
FROM TX01_Society
这是地图:
public class SocietyMap: ClassMap<Society>
{
public SocietaMap()
{
Table("QX01_Society");
ReadOnly();
Id(x => x.Id)
.Column("Kint_QX01_IDSociety");
Map(x => x.Description)
.Column("nvc_QX01_Society");
Map(x => x.IsValid)
.Column("bit_QX01_Valid");
}
}
这是我构建SessionFactory
var cfg = new NHibernate.Cfg.Configuration();
cfg.Configure(); // read config default style
_sessionFactory = Fluently.Configure(cfg)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TagMap>())
.ExposeConfiguration(config => new SchemaExport(config).Create(true, true))
.BuildSessionFactory();
最后一个语句返回:
There is already an object named 'QX01_Society' in the database.