我在一个非常小的控制台应用程序中有以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
namespace test
{
class Program
{
static void Main(string[] args)
{
var factory = CreateSessionFactory();
var session = factory.OpenSession();
Console.Write("done");
Console.Read();
}
static ISessionFactory CreateSessionFactory()
{
string csStringName = Environment.MachineName;
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c.FromConnectionStringWithKey(csStringName)))
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(StatusCode))))
.BuildSessionFactory();
return cfg;
}
}
}
一切看起来都不错,跟着Tekpub上的例子,然而当我去构建时,我松开了所有的VS颜色,我得到以下错误:
Error 1 The type or namespace name 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?) C:\PROJECTS TEST\test\test\Program.cs 6 7 test
Error 2 The type or namespace name 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?) C:\PROJECTS TEST\test\test\Program.cs 7 7 test
Error 3 The type or namespace name 'NHibernate' could not be found (are you missing a using directive or an assembly reference?) C:\PROJECTS TEST\test\test\Program.cs 8 7 test
Error 4 The type or namespace name 'ISessionFactory' could not be found (are you missing a using directive or an assembly reference?) C:\PROJECTS TEST\test\test\Program.cs 21 16 test
我觉得这很奇怪,这似乎不起作用,但仅限于在控制台应用程序中,因为我在另一个更大的项目中工作,我试图从XML转换为Fluent。
任何想法?
编辑这个问题似乎与VS 2010有关,如果我试图在2008年建立这个项目它构建良好。我仍然想知道为什么它会在一个而不是另一个中起作用。