_myList = ne...">

Nhibernate: QuerySyntaxException: "Class" is not displayed

I have the following class:

public class MyClass
{
    private List<long> _myList = new List<long>();

    public virtual string MyID { get; set; }

    public virtual string MyData
    {
        get
        {
            return SomeStaticClass.Serialize(_myList);
        }
        set
        {
            _myList = SomeStaticClass.Deserialize<List<long>>(value);
        }
    }

    public virtual List<long> MyList
    {
        get { return _myList; }
    }
}

And the following mapping file:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="MyNamespace"
               namespace="MyNamespace">
  <class name="MyNamespace.MyClass" table="MY_TABLE">
    <id name="MyID" column="MY_ID" type="System.String">
      <generator class="assigned"></generator>
    </id>
    <property name="MyData" column="MY_DATA"></property>
  </class>
</hibernate-mapping>

When I try to run the following line:

session.Delete("From MyClass m");

I get a QuerySyntaxException with the message "MyClass is not displayed [From MyClass s]".

When I change the field name "MyID" to "ID" in the mapping file, the exception becomes

NHibernate.PropertyNotFoundException: Failed to find getter for property id in class 'MyNamespace.MyClass'.

, . , , , . ? , MyList, , , .

EDIT: , MyData MyList . - .

2: get; ; . . , nhibernate , , , PropertyNotFound "class in not mapping".

+3
7

hbms? , , Visual Studio

+8

session.Delete("From MyNamespace.MyClass m");

HQL , cat , Eg.Cat.

+5

<class name="MyClass" table="MY_TABLE">

, :

session.CreateQuery("from MyClass")

:

session.CreateQuery("from MY_TABLE")
+5

, "Build Action of the File" "Embedded Resource".

+3

*.hbm.xml .

1]

+3

. hbm XML.

+1

it seems a little strange that you specify the namespace twice in the mapping file. I would try just specifying the name attribute as "MyClass" instead of "MyNamespace.MyClass", so it would be

<class name="MyClass" table="MY_TABLE">
0
source

Source: https://habr.com/ru/post/1712983/


All Articles