Page 1 of 1

Entity Developer Update DB(SQLite) from model

Posted: Sun 18 Apr 2021 10:33
by Android71
In Model I have generated

public partial class ControlSpace {

public ControlSpace()
{
this.LightElements = new List<LightElement>();
this.ControlDevices = new List<ControlDevice>();
OnCreated();
}


public virtual short Id { get; set; }

public virtual string Name { get; set; }

public virtual IList<LightElement> LightElements { get; set; }

public virtual IList<ControlDevice> ControlDevices { get; set; }

#region Extensibility Method Definitions

partial void OnCreated();

#endregion
}

when I do Update Database From Model Command (Database - SQLite)

for this class ED tool make this DDL

CREATE TABLE "main".ControlSpaces (
Id INTEGER NOT NULL,
Name TEXT NOT NULL,
CONSTRAINT PK_ControlSpaces PRIMARY KEY (Id)
);

after this command Id field in ControlSpaces table does not become autoincremented.
If i change command with this DLL

CREATE TABLE ControlSpaces (
Id INTEGER CONSTRAINT PK_ControlSpaces PRIMARY KEY AUTOINCREMENT
NOT NULL,
Name TEXT NOT NULL
);

Id field - autoincremented

How to make this with Entity Developer?

I try using data attribute
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
for Id field - this did not help.

Re: Entity Developer Update DB(SQLite) from model

Posted: Mon 19 Apr 2021 13:04
by Shalex
You are working with EF Core, aren't you? Please open Property Editor for your Id property and set Value Generated=OnAdd, save the model and try generating SQL again.