Do I have to implement Add/Delete methods in my NHibernate entities ?

Posted by Lisa on Stack Overflow See other posts from Stack Overflow or by Lisa
Published on 2011-01-08T09:16:58Z Indexed on 2011/01/08 9:54 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

This is a sample from the Fluent NHibernate website:

Compared to the Entitiy Framework I have ADD methods in my POCO in this code sample using NHibernate. With the EF I did context.Add or context.AddObject etc... the context had the methods to put one entity into the others entity collection!

Do I really have to implement Add/Delete/Update methods (I do not mean the real database CRUD operations!) in a NHibernate entity ?

public class Store
{
  public virtual int Id { get; private set; }
  public virtual string Name { get; set; }
  public virtual IList<Product> Products { get; set; }
  public virtual IList<Employee> Staff { get; set; }

  public Store()
  {
    Products = new List<Product>();
    Staff = new List<Employee>();
  }

  public virtual void AddProduct(Product product)
  {
    product.StoresStockedIn.Add(this);
    Products.Add(product);
  }

  public virtual void AddEmployee(Employee employee)
  {
    employee.Store = this;
    Staff.Add(employee);
  }
}

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about methods