English 中文(简体)
我怎样才能获得一份清单,列出在NHibernate的哪些实体,其中父母可以提及不同的表格。
原标题:How can I get a list of entities in NHibernate where the ParentId might refer to different tables

我是新到恩赫特的,因此我确信,我只是空谈一些根本问题。

我有一个称为“问题”的表格,有一个括号。 父母 d 系指不同的表格(即项目或客户等)。 我怎样才能在恩赫伯特这样做,以便我只能够表明属于项目的问题。 这是我所尝试的。

            DetachedCriteria dCriteria = DetachedCriteria.For<Issue>("issue")
            .SetProjection(Projections.Property("ParentId"))
            .CreateAlias("Project", "project", NHibernate.SqlCommand.JoinType.InnerJoin)
            .Add(Restrictions.EqProperty("issue.ParentId", "project.Id"))
            ;
        var issues = Session.CreateCriteria<Issue>("issue")
                .Add(Subqueries.Exists(dCriteria)).List<Issue>();
        return issues;

我的绘图工作就是这样。 我没有提及母物体,因为我不知道会是什么。

    <class name="Issue" table="dbo.Issue" lazy="true">
    <id name="Id" column="Id">
        <generator class="assigned" />
    </id>

    <property name="ParentId" column="ParentId" />

    <property name="Name" />

    <property name="Description" />

I would appreciate any guidance.

也许我还要作一点解释。 我有所有问题的网格,我想显示一栏,这样我们就知道哪类问题(项目等),该栏除显示的其他用途外,还没有任何其他用途,因此我认为,在数据库中添加这一字句是不有效的。 在结构中,很容易通过吸收或利用外部专家来过滤数据。 恩赫伯特必须采用类似方法,因此我不必走过每一个路。 项目涉及所有问题。

最佳回答

这是一个可怕的设计。 您至少应使用不同的关系栏或另一栏,确定哪类或母物体。

如果你这样做,你将能够与NHibernate绘制地图。

如果你能够出于某种原因,也许会发现什么是你所期望的。

问题回答
  1. 页: 1 这种方法采用数据计算方法。 有了NHibernate,你就使用真正的喷气机或收集真实物体来代表这些关系。 Nhibernate take care of the foreign Keys in You DB auto

  2. 我将使用接口或基类来代表可以用作母子的不同物品,如果你真需要与母子联系的话。 但是,你可能不会 t,因为你很可能是 customer,例如客户,然后通过这些问题进行。

  3. Assigned Ids are generally a bad idea. Better to use something like HiLo or the the DBs Native generator.

例如,贵方的物体可能照此办理:

public class Issue
{
   public int Id{ get; set; }
   public IHazIssues Parent { get; set; } //If you really need this
   public string Name { get; set; }
   public string Description { get; set; }
}

public class Customer : IHazIssues 
{
   public int Id{ get; set; }
   public IList<Issue> Issues { get; set; }
   public string NAme{ get; set; }
}

//If you don t need the parent mapping on Item you don t need this.
public interface IHazIssues 
{
   IList<Issue> Issues { get; set; }
}

......





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签