https://github.com/joshclose/fluentdatabase
A .NET library created in C# to fluently create any type of database
https://github.com/joshclose/fluentdatabase
Last synced: over 1 year ago
JSON representation
A .NET library created in C# to fluently create any type of database
- Host: GitHub
- URL: https://github.com/joshclose/fluentdatabase
- Owner: JoshClose
- License: ms-pl
- Created: 2009-08-18T14:35:00.000Z (almost 17 years ago)
- Default Branch: master
- Last Pushed: 2009-08-20T19:27:20.000Z (almost 17 years ago)
- Last Synced: 2025-03-01T18:01:49.422Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 133 KB
- Stars: 79
- Watchers: 19
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE.txt
Awesome Lists containing this project
README
FluentDatabase is a library to fluently create a number of different database types.
Currently supported databases are:
- Access
- Firebird
- MySQL
- Oracle
- PostgreSQL
- SQLite
- SQLServer
Example:
DatabaseFactory.Create( databaseType )
.WithName( "Business" )
.UsingSchema( "Test" )
.HasTable(
table => table
.WithName( "Companies" )
.HasColumn(
column => column.WithName( "Id" ).OfType( SqlDbType.Int ).IsAutoIncrementing()
.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
.HasConstraint(
constraint => constraint.OfType( ConstraintType.PrimaryKey ).WithName( "PK_Companies_Id" ) )
)
.HasColumn(
column => column.WithName( "Name" ).OfType( SqlDbType.NVarChar, 100 )
.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
)
)
.HasTable(
table => table
.WithName( "Employees" )
.HasColumn(
column => column.WithName( "Id" ).OfType( SqlDbType.Int ).IsAutoIncrementing()
.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
.HasConstraint(
constraint => constraint.OfType( ConstraintType.PrimaryKey ).WithName( "PK_Employees_Id" ) )
)
.HasColumn(
column => column.WithName( "CompanyId" ).OfType( SqlDbType.Int )
.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
.HasConstraint(
constraint =>
constraint.WithName( "FK_Employees_CompanyId" ).OfType( ConstraintType.ForeignKey ).HasReferenceTo( "Companies", "Id" ) )
)
.HasColumn(
column => column.WithName( "Name" ).OfType( SqlDbType.NVarChar, 50 )
.HasConstraint( constraint => constraint.OfType( ConstraintType.NotNull ) )
)
.HasColumn(
column => column.WithName( "Bio" ).OfType( SqlDbType.NVarChar, ColumnSize.Max )
)
).Write( writer );
Creates the script:
USE [Business]
CREATE TABLE [Test].[Companies]
(
[Id] INT IDENTITY NOT NULL CONSTRAINT [PK_Companies_Id] PRIMARY KEY,
[Name] NVARCHAR ( 100 ) NOT NULL,
)
CREATE TABLE [Test].[Employees]
(
[Id] INT IDENTITY NOT NULL CONSTRAINT [PK_Employees_Id] PRIMARY KEY,
[CompanyId] INT NOT NULL CONSTRAINT [FK_Employees_CompanyId] FOREIGN KEY REFERENCES [Test].[Companies] ( [Id] ),
[Name] NVARCHAR ( 50 ) NOT NULL,
[Bio] NVARCHAR ( MAX ),
)