流畅的 NHibernate 控制台应用程序

发布于 2024-09-14 09:24:18 字数 2064 浏览 4 评论 0原文

我在一个非常小的控制台应用程序中有以下代码:

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 年构建这个项目,它构建得很好。我仍然想知道为什么它适用于一种而不适用于另一种。

I Have the Following Code in a VERY small Console App:

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;
        }
    }
}

Everything looks fine, following along on example on Tekpub, however when I go to build I loose all the VS colors and I get the following Errors:

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

I find it so strange that this seems not to work but ONLY when inside a Console App as I have it working in another larger project that I am attempting to convert from XML to Fluent.

Any Ideas ?

EDIT the issue seems to be something to do with VS 2010 if I attempt to build this project in 2008 it builds fine. I would still like to know why it would work in one and not the other.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文