Hi I'm new to Hibernate. Have borrowed the book 'Hibernate in Action' plus read the NHibernate docs but still confused as to creating mapping files.. I enclose my code. Can anyone help..?
/*
CREATE TABLE [dbo].[tblInvestment](
[InvestmentId] [int] IDENTITY(1,1) NOT NULL,
[InvestmentName] [varchar](50) NOT NULL,
CONSTRAINT [PK_tblInvestments] PRIMARY KEY CLUSTERED
(
[InvestmentId] ASC
)
CREATE TABLE [dbo].[tblAsset](
[AssetId] [int] IDENTITY(1,1) NOT NULL,
[AssetName] [varchar](50) NOT NULL,
[InvestmentId] [int] NOT NULL,
[AssetValue] [Currency] NOT NULL,
CONSTRAINT [PK_tblAsset] PRIMARY KEY CLUSTERED
(
[AssetId] ASC
)
ALTER TABLE [dbo].[tblAsset] WITH CHECK ADD
CONSTRAINT [FK_tblAsset_tblInvestment] FOREIGN KEY([InvestmentId])
REFERENCES [dbo].[tblInvestment] ([InvestmentId])
GO
ALTER TABLE [dbo].[tblAsset] CHECK CONSTRAINT [FK_tblAsset_tblInvestment]
*/
using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using Iesi.Collections;
namespace MyNamespace
{
public class Investment
{
private int id;
private string name;
private PortfolioOfAssets portfolioOfAssets;
public virtual string Name
{
get { return name; }
set { name = value;}
}
public virtual int Id
{
get { return id; }
set { id = value;}
}
public virtual PortfolioOfAssets PortfolioOfAssets
{
get { return PortfolioOfAssets; }
set { PortfolioOfAssets = value; }
}
public Investment()
{
this.portfolioOfAssets = new PortfolioOfAssets();
}
}
public class PortfolioOfAssets
{
private ISet assets = new HashedSet();
private Investment investment;
public virtual ISet Assets
{
get { return assets; }
set { assets = value; }
}
public Investment Investment
{
get { return investment; }
set { investment = value;}
}
public PortfolioOfAssets()
{}
public decimal GetPortfolioValue()
{
decimal result = 0.0M;
foreach(Asset asset in Assets)
{
result += asset.AssetValue;
}
return result;
}
}
public class Asset
{
private PortfolioOfAssets portfolioOfAssets;
private string name;
private decimal assetValue;
public PortfolioOfAssets PortfolioOfAssets
{
get { return PortfolioOfAssets; }
set { portfolioOfAssets = value;}
}
public virtual string Name
{
get { return name; }
set { name = value;}
}
public virtual decimal AssetValue
{
get { return assetValue; }
set { assetValue=value;}
}
}
}
|