I create a database from scratch using T-SQL (this code works).
As we can see, the graph use $node_id in T-SQL which looks like an alias of the full name $NodeIdE051E8F24C3E4C19A168DDEF0BAA40A7. This unique ID changes each time I create the DB. The T-SQL script always works.
CREATE DATABASE TestGraph
ALTER DATABASE TestGraph MODIFY FILE
( NAME = N'TestGraph', SIZE = 32MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5MB )
GO
ALTER DATABASE TestGraph MODIFY FILE
( NAME = N'TestGraph_log', SIZE = 32MB, MAXSIZE = UNLIMITED, FILEGROWTH = 10% )
GO
use "TestGraph"
go
exec sp_configure 'contained database authentication', 1
go
reconfigure
go
alter database "TestGraph"
set containment = partial
go
CREATE USER testuser WITH PASSWORD = '$Password1234'
EXEC sp_addrolemember 'db_datareader', 'testuser';
EXEC sp_addrolemember 'db_datawriter', 'testuser';
go
CREATE TABLE Species
(
[Id] int IDENTITY(1,1) NOT NULL,
[TranslatedNameId] int NULL,
[ImageIndex] int NULL,
[Name] nvarchar(64),
[Description] nvarchar(max) NULL,
PRIMARY KEY (Id)
) AS NODE;
CREATE TABLE ChildSpeciesLink AS EDGE;
CREATE TABLE AncestorSpeciesLink AS EDGE;
Insert Species (Name, Description) VALUES
(N'Racine', N'Racine de l''arbre.'),
(N'Chat', N'Chat'),
(N'Chien', N'Chien'),
(N'Furet', N'Furet'),
(N'Rat', N'Rat');
Insert into ChildSpeciesLink ($to_id,$from_id) values
-- Race Chat:
(
(select $node_id from dbo.Species where Id=1),
(select $node_id from dbo.Species where Id=2)
),
-- Race Chien:
(
(select $node_id from dbo.Species where Id=1),
(select $node_id from dbo.Species where Id=3)
);
Insert into AncestorSpeciesLink ($to_id,$from_id) values
-- Race Chat:
(
(select $node_id from dbo.Species where Id=2),
(select $node_id from dbo.Species where Id=1)
),
-- Race Chien:
(
(select $node_id from dbo.Species where Id=3),
(select $node_id from dbo.Species where Id=1)
);
But the problem is after, with Entity Developer. The generated class use the full name so I must resync C# code on database and rebuild project. Is there a way to avoid this ?
Here is the generated code :
public partial class Species
{
public Species()
{
OnCreated();
}
public string NodeIdE051E8F24C3E4C19A168DDEF0BAA40A7 { get; set; }
/// <summary>
/// Clé primaire.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Numéro de ressource externe pour la localisation.
/// </summary>
public int? TranslatedNameId { get; set; }
/// <summary>
/// Numéro d'image pour un rendu plus visuel de la donnée.
/// </summary>
public int? ImageIndex { get; set; }
/// <summary>
/// Nom de l'espèce concernée.
/// </summary>
public string Name { get; set; }
public string Description { get; set; }
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
}
Thanks for help. Vincent
We will add the feature of detecting and truncating the GUID suffix in columns' names when importing graph tables into Devart EF Core Model and notify you.