I have the following pretty simple code:
using System;
using System.Data.Entity;
namespace TestCSharp
{
public class Testee
{
public long Id { get; set; }
public string Name { get; set; }
public Testee()
{
}
public Testee(long id, string name)
{
Id = id;
Name = name;
}
}
public class DatabaseContext : DbContext
{
public DatabaseContext()
: base("name=MyContext")
{
}
public DbSet<Testee> Testees { get; set; }
}
class Program
{
static void Main(string[] args)
{
var dbContext = new DatabaseContext();
var testData = new Testee(0, "name");
dbContext.Testees.Add(testData);
dbContext.SaveChanges();
Console.WriteLine("Id: {0}", testData.Id);
}
}
}
And I assume that it should print 0
but in fact it prints 1
. If I used any other value except 0
then I would get that value. And it adds a row with 1
not 0
as I ask it. What is the problem with zero value? I'm absolutely new to both EF and SQL CE but that looks like a bug, no?
I use the latest available Nuget packages for EF(6.x) and SQL CE(4.x) on desktop Windows 8.1.
UPD: Create table script:
CREATE TABLE [Testees] (
[Id] bigint IDENTITY (1,1) NOT NULL
, [Name] nvarchar(4000) NULL
);
GO
ALTER TABLE [Testees] ADD CONSTRAINT [PK_dbo.Testees] PRIMARY KEY ([Id]);
GO