Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent Nhibernate自动映射和GUID/UniqueIdentifier作为主键字段的问题_Nhibernate_Fluent Nhibernate_Automapping_Fluent Interface - Fatal编程技术网

Fluent Nhibernate自动映射和GUID/UniqueIdentifier作为主键字段的问题

Fluent Nhibernate自动映射和GUID/UniqueIdentifier作为主键字段的问题,nhibernate,fluent-nhibernate,automapping,fluent-interface,Nhibernate,Fluent Nhibernate,Automapping,Fluent Interface,我试图使用Fluent NHibernate自动映射功能(在软件的最新版本中),但在使用GUI作为主键字段时遇到了问题。如果我对主键使用整数字段,那么表将成功生成,并且所有Nhibernate功能似乎都可以正常工作。仅供参考,我正在使用NHibernate生成我的数据库表 下面是几个具有整数ID的类 using System; using System.Collections; using System.Collections.Generic; using System.ComponentMod

我试图使用Fluent NHibernate自动映射功能(在软件的最新版本中),但在使用GUI作为主键字段时遇到了问题。如果我对主键使用整数字段,那么表将成功生成,并且所有Nhibernate功能似乎都可以正常工作。仅供参考,我正在使用NHibernate生成我的数据库表

下面是几个具有整数ID的类

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Reflection;

namespace Sample.Data.Entities
{
    public class Employee
    {
        public virtual int Id { get; private set; }
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual Store Store { get; set; }
    }

    public class Product
    {
        public virtual int Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual double Price { get; set; }
        public virtual IList<Store> StoresStockedIn { get; private set; }

        public Product()
        {
            StoresStockedIn = new List<Store>();
        }
    }

    public class Store
    {
        public virtual int Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual IList<Product> Products { get; set; }
        public virtual IList<Employee> Staff { get; set; }

        public Store()
        {
            Products = new List<Product>();
            Staff = new List<Employee>();
        }

        public virtual void AddProduct(Product product)
        {
            product.StoresStockedIn.Add(this);
            Products.Add(product);
        }

        public virtual void AddEmployee(Employee employee)
        {
            employee.Store = this;
            Staff.Add(employee);
        }
    }
}
此外,如果我关闭自动映射并使用流畅配置的映射,则会成功生成表

这让我发疯,我相信这可能是一个快速解决办法。有什么想法吗

谢谢大家!


Anthony

显然,流畅的Nhibernate 1.0RC版和1.0版存在问题。但是,如果您从SVN主干下载最新版本,一切都会完美运行。看来问题只是代码中的一个bug,现在已经被纠正了


另外,我应该注意到詹姆斯·格雷戈里、保罗·巴图姆,也许还有其他人,正在积极地学习流利的NHibernate。该产品的发展非常迅速,在过去几个月里,代码发生了重大变化。

显然,Fluent Nhibernate 1.0RC版和1.0版存在问题。但是,如果您从SVN主干下载最新版本,一切都会完美运行。看来问题只是代码中的一个bug,现在已经被纠正了


另外,我应该注意到詹姆斯·格雷戈里、保罗·巴图姆,也许还有其他人,正在积极地学习流利的NHibernate。该产品的发展非常迅速,在过去的几个月里,代码发生了重大变化。

感谢您回来通知我们,问题已经解决了。因此,我们知道今天这个问题并没有困扰任何人。感谢您回来通知我们,这个问题已经解决了。因此,我们知道,这并没有困扰今天的任何人。
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Reflection;

namespace Sample.Data.Entities
{
    public class Employee
    {
        public virtual Guid Id { get; private set; }
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual Store Store { get; set; }
    }

    public class Product
    {
        public virtual Guid Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual double Price { get; set; }
        public virtual IList<Store> StoresStockedIn { get; private set; }

        public Product()
        {
            StoresStockedIn = new List<Store>();
        }
    }

    public class Store
    {
        public virtual Guid Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual IList<Product> Products { get; set; }
        public virtual IList<Employee> Staff { get; set; }

        public Store()
        {
            Products = new List<Product>();
            Staff = new List<Employee>();
        }

        public virtual void AddProduct(Product product)
        {
            product.StoresStockedIn.Add(this);
            Products.Add(product);
        }

        public virtual void AddEmployee(Employee employee)
        {
            employee.Store = this;
            Staff.Add(employee);
        }
    }
}
    return Fluently.Configure()
      .Database(MsSqlConfiguration.MsSql2008
      .ConnectionString(c => c.FromConnectionStringWithKey("AAAConnectionString"))
      .UseReflectionOptimizer()              
      .AdoNetBatchSize(25)
      .DefaultSchema("dbo")
      .Cache(c => c
        .UseQueryCache()
        .ProviderClass<HashtableCacheProvider>())
      .ShowSql())
      .Mappings(m=>m.AutoMappings
        .Add(AutoMap.AssemblyOf<Sample.Data.Entities.Product>()                
        .Where(type => type.Namespace == "Sample.Data.Entities.Product")
        .Conventions.AddFromAssemblyOf<Sample.Data.Fluent.Conventions.PrimaryKeyNameConvention>()
        ))
      .ExposeConfiguration(BuildSchema)              
      .BuildSessionFactory();
public class PrimaryKeyNameConvention : IIdConvention
{
    public bool Accept(IIdentityInstance id)
    {
        return true;
    }
    public void Apply(IIdentityInstance id)
    {
        id.Column("Id");                
    }
}

public class PrimaryKeyGeneratorConvention : IIdConvention
{
    public bool Accept(IIdentityInstance id)
    {
        return true;
    }
    public void Apply(IIdentityInstance id)
    {
        id.GeneratedBy.GuidComb();
    }
}