0

I have a table which looks like:

[dbo].[Person](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](150) NULL,
    [SysDate] [datetime] NOT NULL CONSTRAINT [DF_Person_SysDate]  DEFAULT (getdate())

In my Wcf service I'm using entity framework but it doesn't work properly i.e. it is not saving the data model when the table has default field value.

Working solution which is not acceptable:

public void InsertPerson(Person model)
{
   using (DbEntities db = new DbEntities())
   {
      db.AddToPerson(new Person() { Name = model.Name, SysDate = DateTime.Now });
      db.SaveChanges();
   }
}

Non working solution - solution which I'm tring to achieve:

public void InsertPerson(Person model)
{
   using (DbEntities db = new DbEntities())
   {
      db.AddToPerson(model);
      db.SaveChanges();
   }
}
ToTa
  • 3,304
  • 2
  • 19
  • 39

1 Answers1

1

Would you please include any error information you get from the debugger when it fails in the 'Non working solution - solution which I'm tring to achieve:'

Also please try the following and see if this works.

public void InsertPerson(Person model)
{
   using (DbEntities db = new DbEntities())
   {
      db.Entry(model).State = System.Data.Entity.EntityState.Added;
      db.SaveChanges();
   }
}

I hope it helps.

Entvex
  • 35
  • 1
  • 1
  • 9