Mine is here:
Error is :
NHibernate.MappingException: composite-id class must override Equals
(): Competency.Domain.AccessibleDocumentsDto
NHibernate.MappingException: Could not compile the mapping document:
(XmlDocument)
public class AccessibleDocumentsDto
{
public virtual int RoleId { get; set; }
public virtual int DocId { get; set; }
public virtual bool WithAccess { get; set; }
}
public class AccessibleDocumentsDtoMap :
ClassMap<AccessibleDocumentsDto>
{
public AccessibleDocumentsDtoMap()
{
WithTable("dbo.RoleDocument");
UseCompositeId()
.WithKeyProperty(x => x.RoleId, "RoleID")
.WithKeyProperty(x => x.DocId, "DocID");
Map(x => x.WithAccess)
.FormulaIs("case when AllowFullAccess = 1 or AllowEdit
= 1 or AllowRead = 1 or AllowView = 1 then 1 else 0 end");
}
}
XMB File:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Entities.RoleDocument, Entities"
table="dbo.RoleDocument">
<composite-id name="Id" class="Entities">
<key-property name="DocID" column="DocID" type="System.Int32"/>
<key-property name="RoleID" column="RoleID" type="System.Int32"/>
</composite-id>
<property name="AllowEdit" column="AllowEdit" type="System.Boolean"
not-null="true"/>
<property name="AllowFullAccess" column="AllowFullAccess"
type="System.Boolean" not-null="true"/>
<property name="AllowRead" column="AllowRead" type="System.Boolean"
not-null="true"/>
<property name="AllowView" column="AllowView" type="System.Boolean"
not-null="true"/>
</class>
</hibernate-mapping>
SCHEMA:
CREATE TABLE [dbo].[RoleDocument](
[RoleID] [int] NOT NULL,
[DocID] [int] NOT NULL,
[AllowFullAccess] [bit] NOT NULL CONSTRAINT
[DF_RoleDocument_AllowFullAccess] DEFAULT (0),
[AllowEdit] [bit] NOT NULL CONSTRAINT [DF_RoleDocument_AllowEdit]
DEFAULT (0),
[AllowRead] [bit] NOT NULL CONSTRAINT [DF_RoleDocument_AllowRead]
DEFAULT (0),
[AllowView] [bit] NOT NULL CONSTRAINT [DF_RoleDocument_AllowView]
DEFAULT (0),
CONSTRAINT [PK_RoleDocument] PRIMARY KEY CLUSTERED
(
[RoleID] ASC,
[DocID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 90) ON
[PRIMARY]
) ON [PRIMARY]
But if I use this Map:
public class AccessibleDocumentsDtoMap :
ClassMap<AccessibleDocumentsDto>
{
public AccessibleDocumentsDtoMap()
{
WithTable("dbo.RoleDocument");
Id(x => x.RoleId)
.TheColumnNameIs("RoleID")
.GeneratedBy.Assigned();
Map(x => x.DocId)
.ColumnName("DocID")
.Not.Nullable();
Map(x => x.WithAccess)
/.FormulaIs("case when AllowFullAccess = 1 or
AllowEdit = 1 or AllowRead = 1 or AllowView = 1 then 1 else 0 end");
}
}
All returned results are all duplicates, If we say it returns 100
records, all that 100 are identical. =(
I was suppose to ask you on twitter, if there are writing about
"UseCompositeId()" =)