0

I am a beginning at nhibernate and I am trying to connect to a pre-existing database table using fluent-nhibernate. The table has no id field, and I am stuck as to how to get queries to work. I get an error - "Field ID does not exist in ".

The table is in a DB2 database, so some of tools for autogenerating code are not applicable.

Update

The file and the class looks rather like the following (where where WHO is the primary key)

public class Nougal
{
    public virtual string WHO { get; set; }
    public virtual string YN1 { get; set; }
    public virtual string YN2 { get; set; }
    public virtual string YN3 { get; set; }
    public virtual string YN4 { get; set; }
4

2 回答 2

1

You must have some sort of id in order to have NH properly mapping your table as an entity to fit it properly in the identity map of the session. Usually this is represented by the primary key in your table. Even if not defined in the table try to identify what distinguish each record and map it as the table identifier. This could possibly be a composite-id.

于 2012-06-12T15:29:55.960 回答
1

I have it working, I had to create a map, and point the Id field at the column that is being used as primary key.

public class FILENAMEMap : ClassMap<FILENAME>
{
    public FILENAMEMap()
    {     
        Table("FILENAME");
        Id(x => x.Id).Column("WHO");
        Map(x => x.YN1).Column("YN1");
        Map(x => x.YN2).Column("YN2");

I think that this has done it, so thanks for pointers, etc.

于 2012-06-13T19:32:26.817 回答