Hi,
I'm working with a small model in Entity Framework 4.0. I'd like to have an instance method of the object that represents an entity persist the entity to the database. So instead of from "external" code:
public static void Main(string[] args)
{
using (EFContext ctx = new EFContext())
{
context.AnEntitySet.AddObject(refToTheEntityInstance);
context.SaveChanges();
Instead, I want the instance of the entity to persist itself, where Contact is the entity name.
public ContactInstance : Contact
{
public void Persist(List<AnotherEntity> otherEntityList)
{
using (EFContext ctx = new EFContext())
{
...
ctx.Contacts.AddObject(this); // DOESN'T WORK.
...
...wire up navigation property to collection of AnotherEntity...
ctx.SaveChanges();
I'm doing something wrong. Is this a bad design ? It seems to me that an entity, like any object in object oriented design, should "know" how to persist itseld.
Thabks,
Scott