I am creating WCF to communicate with SAP and have to send arrays of different objects.
Here is an example of DataContracts
[DataContract]
public class MesPet12
{
[DataMember(IsRequired = true, Order = 1)]
public DateTime Date { get; set; }
[DataMember(Name = "Shifts")]
public ShiftMes[] Shifts { get; set; }
}
[DataContract(Name = "Shift")]
public class ShiftMes
{
[DataMember(IsRequired = true, Order = 1)]
public string Id { get; set; }
[DataMember(Order = 2)]
public Order[] Orders { get; set; }
}
In singleWsd there is the following:
<xs:complexType name="MesPet12">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Date" type="xs:dateTime"/>
<xs:element minOccurs="0" maxOccurs="1" name="Shifts" type="tns:ArrayOfShiftMes"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfShiftMes">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="ShiftMes" nillable="true"
type="tns:ShiftMes"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ShiftMes">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="Orders" type="tns:ArrayOfOrder"/>
</xs:sequence>
</xs:complexType>
As you can see the new ComplexType "ArrayOfShiftMes" was generated. Everythings works fine, but as I know SAP doesn't like something like "ArrayOf...".
How can I either avoid creating extra complex type "ArrayOf" or rename it?
If somebody face with the same issue, the solution is the following:
you just need to add the attribute
[System.Xml.Serialization.XmlElementAttribute("Shifts", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ShiftMes[] Shifts { get; set; }
Related
I have a WCF webservice that my C++ client talks to using a proxy generated by svcutil + wsutil.
I added a new DataMember, and now i get:
Serialization failure occurred when reading an element with WS_READ_OPTION '2', name 'GetMachineRequestDetailsResponse' and namespace 'M.NativeOM'.; Serialization failure occurred when reading a field with WS_TYPE '26 (0x1A)', WS_FIELD_MAPPING '2', name 'GetMachineRequestDetailsResult' and namespace 'M.NativeOM'.; An error occurred at row 1, column 796 (0x31C) when the XML reader is processing the input source.; An end element was expected.; A start element with the name 'UseForRun_SnapshotID' and namespace 'M.NativeOM' was found, but not expected.;
My data members with in a datacontract is defined using Order attribute:
[DataMember(Order = 4)]
public int MachineID { get; set; }
[DataMember(Order = 5)]
public string MachineName { get; set; }
[DataMember(Order = 3)]
public bool IsReserved { get; set; }
[DataMember(Order = 13)]
public string ReservedBy { get; set; }
[DataMember(Order = 12)]
public MdMachineRequestType RequestType { get; set; }
[DataMember(Order = 0)]
public bool CommandIsAdmin { get; set; }
[DataMember(Order = 1)]
public string CommandLine { get; set; }
[DataMember(Order = 2)]
public int CommandTimeout { get; set; }
[DataMember(Order = 7)]
public string MoveToDb_ServerName { get; set; }
[DataMember(Order = 6)]
public string MoveToDb_DatabaseName { get; set; }
[DataMember(Order = 11)]
public int Reimage_OsID { get; set; }
[DataMember(Order = 8)]
public int Reimage_ImageID { get; set; }
[DataMember(Order = 9)]
public int Reimage_OptionTimeout { get; set; }
[DataMember(Order = 10)]
public string Reimage_OptionUserName { get; set; }
[DataMember(Order = 15)]
public int UseForRun_RunID { get; set; }
[DataMember(Order = 14)]
public bool UseForRun_DoCleanInstall { get; set; }
[DataMember(Order = 16)]
public int UseForRun_SnapshotID { get; set; }
Also, the generated xsd file shows them in the right sequence
<xs:complexType name="MdMachineRequest">
<xs:sequence>
<xs:element minOccurs="0" name="CommandIsAdmin" type="xs:boolean" />
<xs:element minOccurs="0" name="CommandLine" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="CommandTimeout" type="xs:int" />
<xs:element minOccurs="0" name="IsReserved" type="xs:boolean" />
<xs:element minOccurs="0" name="MachineID" type="xs:int" />
<xs:element minOccurs="0" name="MachineName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="MoveToDb_DatabaseName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="MoveToDb_ServerName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Reimage_ImageID" type="xs:int" />
<xs:element minOccurs="0" name="Reimage_OptionTimeout" type="xs:int" />
<xs:element minOccurs="0" name="Reimage_OptionUserName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Reimage_OsID" type="xs:int" />
<xs:element minOccurs="0" name="RequestType" type="tns:MdMachineRequestType" />
<xs:element minOccurs="0" name="ReservedBy" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="UseForRun_DoCleanInstall" type="xs:boolean" />
<xs:element minOccurs="0" name="UseForRun_RunID" type="xs:int" />
<xs:element minOccurs="0" name="UseForRun_SnapshotID" type="xs:int" />
</xs:sequence>
</xs:complexType>
So using Order attribute did put DataMembers in the right sequence but my client doesn't just ignore new DataMember and instead give an error.
the problem was that when i create proxy using wsutil, i was missing /ignoreTrailingContent option
I have a Class that has two bags.
One bag is with a collection of a class and it works, the other is a collection of long values and this one is not persisted.
I've searched all the web for this and my mappings appears to be OK.
In my mapping I have this:
<class name="Event" table="Events">
<id name="Id" type="Int32">
<generator class="native" />
</id>
<property name="Name" />
<property name="Owner" />
<many-to-one name="DeliveryAddress" column="DeliveryAddressId" cascade="save-update, persist" />
<many-to-one name="EventAddress" column="EventAddressId" cascade="save-update, persist" />
<bag name="Friends" table="Event_Friends" lazy="false" inverse="true" cascade="save-update, persist" fetch="join">
<key column="EventId" />
<element column="Friend" type="Int64" />
</bag>
<bag name="Products" table="Event_Products" lazy="false" inverse="true" cascade="all,delete-orphan" fetch="join">
<key column="EventId" />
<one-to-many class="Product" />
</bag>
</class>
When I call SabeOrUpdate in my session NHibernate create both adresses, create the event and all the products, but the friends list is not saved.
After the save I issue an Get, and the select on the database is correct.
I don't know what else can be.
My model for this mapping is this:
public class Event
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Int64 Owner { get; set; }
public virtual Address DeliveryAddress { get; set; }
public virtual Address EventAddress { get; set; }
public virtual ICollection<Int64> Friends { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
and my database looks like this:
Events
-------------------------------
Id int identity
Name varchar
Owner long
DeliveryAddressId int
EventAddressId int
Address
-------------------------------
Id int
-- Code Abbreviated --
Event_Products
-------------------------------
Id int
EventId int
-- Code Abbreviated --
Event_Friends
-------------------------------
EventId int
Friend long
You should change inverse to false for your collection of longs
<bag name="Friends" table="Event_Friends" lazy="false" inverse="false" cascade="save-update, persist" fetch="join">
<key column="EventId" />
<element column="Friend" type="Int64" />
</bag>
I am having problems deleting an entity from the database using NHibernate v3.
foreach (ShoppingCart s in query )
{
_session.Delete(s);
trans.Commit();
break;
}
"The given key was not present in the dictionary"
There really isn't any more specific information than that. Basically, I'm using two entities as shown below:
| ShoppingCart |==========> | Product |
ShoppingCart PK: ShoppingCartID, ProductID (also is FK)
Product PK: ProductID (no FK)
... A ShoppingCart entity which has many Products inside it.
My ShoppingCart mapping entity look like this:
<class name="ShoppingCart" table="LC_SHOPPINGCART" lazy="true" >
<composite-id>
<key-property name="CartID" column="CARTID" />
<key-property name="ProductID" column="PRODUCTID" />
<key-property name="Size" column="SIZE" />
<key-property name="Color" column="COLOR" />
</composite-id>
<many-to-one foreign-key="ProductID" insert="false" update="false" lazy="false" name="Product">
<column name="PRODUCTID" sql-type="INT" not-null="true" />
</many-to-one>
<property name="Quantity">
<column name="QUANTITY" sql-type="INT" not-null="false" />
</property>
<property name="DateAdded">
<column name="DATEADDED" sql-type="SMALLDATETIME" not-null="false" />
</property>
<property name="Price">
<column name="PRICE" sql-type="MONEY" not-null="false" />
</property>
And the Entity class for ShoppingCart:
public ShoppingCart() { }
[Key]
public virtual string CartID { get; set; }
public virtual int ProductID { get; set; }
public virtual string Size { get; set; }
public virtual string Color { get; set; }
public virtual Product Product { get; set; }
public virtual System.Nullable<int> Quantity { get; set; }
public virtual DateTime DateAdded { get; set; }
public virtual System.Nullable<decimal> Price { get; set; }
My Product Mapping looks like this:
<class name="Product" table="LC_PRODUCT" lazy="true" >
<id name="ProductID" column="ProductID">
<generator class="native"></generator>
</id>
<list name="ShoppingCarts"
cascade="all-delete-orphan">
<key column="ProductID"></key>
<index column="CartID"></index>
<one-to-many class="ShoppingCart"></one-to-many>
</list>
<property name="Name">
<column name="NAME" sql-type="NVARCHAR" not-null="false" />
</property>
<property name="Description">
<column name="DESCRIPTION" sql-type="VARCHAR" not-null="false" />
</property>
<property name="Price">
<column name="PRICE" sql-type="MONEY" not-null="false" />
</property>
<property name="Image1FileName">
<column name="IMAGE1FILENAME" sql-type="NVARCHAR" not-null="false" />
</property>
<property name="Image2FileName">
<column name="IMAGE2FILENAME" sql-type="NVARCHAR" not-null="false" />
</property>
<property name="OnCatalogPromotion">
<column name="ONCATALOGPROMOTION" sql-type="BIT" not-null="false" />
</property>
<property name="OnDepartmentPromotion">
<column name="ONDEPARTMENTPROMOTION" sql-type="BIT" not-null="false" />
</property>
<property name="Sizeable">
<column name="SIZEABLE" sql-type="BIT" not-null="false" />
</property>
<property name="Colorable">
<column name="COLORABLE" sql-type="BIT" not-null="false" />
</property>
<property name="DateAdded">
<column name="DATEADDED" sql-type="SMALLDATETIME" not-null="false" />
</property>
<property name="TotalRemaining">
<column name="TOTALREMAINING" sql-type="INT" not-null="false" />
</property>
</class>
...And the corresponding Product entity class:
public Product() { }
[Key]
public virtual int ProductID { get; set; }
public virtual IList<ShoppingCart> ShoppingCarts { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual System.Nullable<decimal> Price { get; set; }
public virtual string Image1FileName { get; set; }
public virtual string Image2FileName { get; set; }
public virtual bool OnCatalogPromotion { get; set; }
public virtual bool OnDepartmentPromotion { get; set; }
public virtual bool Sizeable { get; set; }
public virtual bool Colorable { get; set; }
public virtual DateTime DateAdded { get; set; }
public virtual System.Nullable<int> TotalRemaining { get; set; }
The stack trace is provided as follows:
Server Error in '/ElectronicsRob' Application.
The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Source Error:
Line 106: //db.lc_ShoppingCarts.DeleteOnSubmit(query);
Line 107: //db.SubmitChanges();
Line 108: new ShoppingCartRepository().DeleteProductFromCart( System.Convert.ToInt32 (Grid1.SelectedDataKey["ProductID"]), LinqShoppingCartAccess.cartID);
Line 109: PopulateControls();
Line 110: }
Source File: c:\inetpub\wwwroot\ElectronicsRob\LINQControls\ControlTemplates\LinqShoppingCart.ascx.cs
Line: 108
Stack Trace:
[KeyNotFoundException: The given key was not present in the dictionary.]
NHibernate.Engine.StatefulPersistenceContext.RemoveEntity(EntityKey key) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\StatefulPersistenceContext.cs:435
NHibernate.Action.EntityDeleteAction.Execute() in d:\CSharp\NH\nhibernate\src\NHibernate\Action\EntityDeleteAction.cs:88
NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:136
NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:125
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in d:\CSharp\NH\nhibernate\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:241
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) in d:\CSharp\NH\nhibernate\src\NHibernate\Event\Default\DefaultFlushEventListener.cs:20
NHibernate.Impl.SessionImpl.Flush() in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:1477
NHibernate.Transaction.AdoTransaction.Commit() in d:\CSharp\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:190
ObjexxRepositories.ShoppingCartRepository.DeleteProductFromCart(Nullable`1 prodID, String cartID) in C:\Users\Rob\Documents\Visual Studio 2010\Projects\NGC6744\ObjexxRepositories\Concrete\ShoppingCartRepository.cs:78
LINQControls_LinqShoppingCart.Grid1_RowDeleting(Object sender, GridViewDeleteEventArgs e) in c:\inetpub\wwwroot\ElectronicsRob\LINQControls\ControlTemplates\LinqShoppingCart.ascx.cs:108
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +814
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +431
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
Any help is appreciated, thank you!
I have two tables in a legacy database that I need to map using NHibernate. Unfortunately, one of these tables are using a composite key and I am running into a problem which I describe below.
Firstly, here is the schema of the two tables:
CREATE TABLE [dbo].[tBenchmarkFxHedgeHistory](
[BenchmarkFxHedgeHistoryId] [int] IDENTITY(1,1) NOT NULL,
[BenchmarkFxHedgeId] [int] NOT NULL,
[ModelId] [int] NOT NULL,
[BaseCurrencyCode] [nvarchar](5) NOT NULL,
[BenchmarkFxHedgeTypeId] [int] NOT NULL,
[DateFrom] [smalldatetime] NOT NULL,
[DateTo] [smalldatetime] NULL,
[PctHedgeBackToBase] [decimal](13, 10) NULL,
[Enabled] [bit] NOT NULL,
[BenchmarkHedgeStatusId] [int] NOT NULL,
[AuditActionId] [int] NOT NULL,
[Timestamp] [timestamp] NOT NULL,
[HistoryUser] [nvarchar](50) NOT NULL CONSTRAINT [DF_tBenchmarkFxHedgeHistory_HistoryUser] DEFAULT (suser_sname()),
[HistoryDate] [datetime] NOT NULL CONSTRAINT [DF_tBenchmarkFxHedgeHistory_HistoryDate] DEFAULT (getdate()),
CONSTRAINT [PK_tBenchmarkFxHedgeHistory] PRIMARY KEY CLUSTERED
(
[BenchmarkFxHedgeHistoryId] ASC
)
CREATE TABLE [dbo].[tBenchmarkFxHedgeRatio](
[BenchMarkFxHedgeId] [int] NOT NULL,
[NonBaseCurrencyCode] [nvarchar](5) NOT NULL,
[PctHedgeBackToBase] [decimal](13, 10) NOT NULL,
CONSTRAINT [PK_tBenchmarkFxHedgeRatio] PRIMARY KEY CLUSTERED
(
[BenchMarkFxHedgeId] ASC,
[NonBaseCurrencyCode] ASC
)
And here are the domain classes:
public class BenchmarkFxHedgeRuleHistory
{
private IList<BenchmarkFxRuleRatioHistory> _percentages = new List<BenchmarkFxRuleRatioHistory>();
public virtual int Id { get; set; }
public virtual string BaseCurrencyCode { get; set; }
public virtual DateTime DateFrom { get; set; }
public virtual DateTime? DateTo { get; set; }
public virtual decimal? Percentage { get; set; }
public virtual bool Enabled { get; set; }
public virtual byte[] Timestamp { get; set; }
public virtual BenchmarkFxHedgeStatus Status { get; set; }
public virtual BenchmarkFxHedgeType Strategy { get; set; }
public virtual Model Model { get; set; }
public virtual BenchmarkFxHedgeRule Rule { get; set; }
public virtual AuditAction AuditAction { get; set; }
public virtual IList<BenchmarkFxRuleRatioHistory> Percentages
{
get { return _percentages; }
}
}
[Serializable]
public class BenchmarkFxRuleRatioHistory
{
public virtual string NonBaseCurrencyCode { get; set; }
public virtual decimal Percentage { get; set; }
public virtual BenchmarkFxHedgeRuleHistory HistoryEntry { get; set; }
public override bool Equals(object obj)
{
var rule = obj as BenchmarkFxRuleRatioHistory;
if (rule == null) return false;
return rule.HistoryEntry.Id == HistoryEntry.Id && NonBaseCurrencyCode == rule.NonBaseCurrencyCode;
}
public override int GetHashCode()
{
return NonBaseCurrencyCode.GetHashCode() ^ HistoryEntry.GetHashCode();
}
}
And finally, here are the NHibernate mapping files:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="Tests.DomainModel" assembly="Tests.DomainModel" xmlns="urn:nhibernate-mapping-2.2">
<class name="BenchmarkFxHedgeRuleHistory" table="`tBenchmarkFxHedgeHistory`" schema="`dbo`">
<id name="Id" access="property" column="`BenchmarkFxHedgeHistoryId`">
<generator class="native" />
</id>
<many-to-one name="Rule" class="BenchmarkFxHedgeRule" column="`BenchmarkFxHedgeId`" not-null="true" fetch="select" />
<property name="BaseCurrencyCode" type="String" column="`BaseCurrencyCode`" length="5" />
<property name="DateFrom" type="DateTime" column="`DateFrom`" />
<property name="DateTo" type="DateTime" column="`DateTo`" />
<property name="Enabled" type="Boolean" column="`Enabled`" />
<property name="Percentage" type="Decimal" column="`PctHedgeBackToBase`" />
<property name="Timestamp" type="BinaryBlob" column="`Timestamp`" />
<many-to-one name="Status" class="BenchmarkFxHedgeStatus" column="`BenchmarkHedgeStatusId`" not-null="true" fetch="join" />
<many-to-one name="Strategy" class="BenchmarkFxHedgeType" column="`BenchmarkFxHedgeTypeId`" not-null="true" fetch="join" />
<many-to-one name="Model" class="Model" column="`ModelId`" not-null="true" fetch="select" />
<many-to-one name="AuditAction" class="AuditAction" column="`AuditActionId`" not-null="true" fetch="join" />
<bag name="Percentages" fetch="join" access="readonly" inverse="true" lazy="false" table="tBenchmarkFxHedgeRatioHistory" cascade="all-delete-orphan" subselect="">
<key column="`BenchmarkFxHedgeHistoryId`" />
<one-to-many class="BenchmarkFxRuleRatioHistory" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="Tests.DomainModel" assembly="Tests.DomainModel" xmlns="urn:nhibernate-mapping-2.2">
<class name="BenchmarkFxRuleRatioHistory" table="`tBenchmarkFxHedgeRatioHistory`" schema="`dbo`">
<composite-id>
<key-property name="NonBaseCurrencyCode" type="String" column="`NonBaseCurrencyCode`" />
<key-many-to-one name="HistoryEntry" class="BenchmarkFxHedgeRuleHistory" column="`BenchmarkFxHedgeHistoryId`" />
</composite-id>
<property name="Percentage" type="decimal" column="`PctHedgeBackToBase`" />
</class>
</hibernate-mapping>
Now I use these in the following code:
using(var session = DataMapperConfiguration.SessionFactory.OpenSession())
{
var sessionRule = session.Get<BenchmarkFxHedgeRule>(id);
var historyList = session.Query<BenchmarkFxHedgeRuleHistory>()
.Where(x => x.Rule == sessionRule).ToList();
Assert.AreEqual(2, historyList[0].Percentages.Count);
}
What happens is that sessionRule is correctly hydrated, but historyList does not have its Percentages property correctly hydrated. It keeps coming back as an empty list, but I expect it to have members in the list since there are matching rows in the database.
Any advice? What could I be doing wrong?
It turns out that the problem was that I declared the Percentages collection as an IList instead of an ICollection. Changing the declaration to ICollection<BenchmarkFxRuleRatioHistory> solves the problem.
Taking the following object model:
public abstract class Entity
{
public Guid Id { get; set; }
}
public class Category : Entity
{
public string Name { get; set; }
public ICollection<LocalizedProperty> LocalizedProperties { get; set; }
}
public class Product : Entity
{
public string Name { get; set; }
public ICollection<LocalizedProperty> LocalizedProperties { get; set; }
}
public class LocalizedProperty : Entity
{
public string CultureName { get; set; }
public string PropertyName { get; set; }
public string PropertyValue { get; set; }
}
Is it possible to use a type discriminator along with the entity's Id as the foreign key. The idea is that the resultant LocalizedProperties table would be:
LocalizedProperties
-------------------
Id
EntityType
EntityId
CultureName
PropertyName
PropertyValue
I know this is possible using Table-per-subclass mapping where each of my "Localized" entities inherit from a base localized entity class, which in turn has the association with LocalizedProperty. However, I would rather not have this extra level of inheritance if the above is possible.
Thanks,
Ben
UPDATE
Thanks to Diego for providing the solution using confORM. For those of you using traditional mapping files, I have converted the example from http://fabiomaulo.blogspot.com/2010/11/conform-any-to-many.html
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="ConfOrm.UsageExamples.CreateXmlMappingsInBinFolder" assembly="ConfOrm.UsageExamples" xmlns="urn:nhibernate-mapping-2.2">
<class name="Blog">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
<property name="Title" />
<property name="Subtitle" />
<set name="Tags" cascade="all" where="TagedItemClass = 'ConfOrm.UsageExamples.CreateXmlMappingsInBinFolder.Blog'">
<key column="TagedItemId" foreign-key="none" />
<one-to-many class="Tag" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="ConfOrm.UsageExamples.CreateXmlMappingsInBinFolder" assembly="ConfOrm.UsageExamples" xmlns="urn:nhibernate-mapping-2.2">
<class name="Tag">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
<property name="Name" />
<any id-type="Guid" name="TagedItem">
<column name="TagedItemClass" />
<column name="TagedItemId" />
</any>
</class>
</hibernate-mapping>
You can use <any>.
http://nhibernate.info/doc/nh/en/index.html#mapping-types-anymapping
For a full example, check http://fabiomaulo.blogspot.com/2010/11/conform-any-to-many.html. I think it's exactly what you need.