Skip to content

Enhancement: Complete support to the Fluent named-based operation #499

@mikependon

Description

@mikependon

RepoDb promises to be the hybrid ORM for .NET. Even though RepoDb supports both Dynamic and Fluent operations, but currently, RepoDb fluent implementation seems to be limited to an Entity Model.

This story would allow the library consumer to use the model (or a DataEntity class) to any table from the database. The intention is, if you have a table with an identical columns with other tables, then you can utilize single model for that.

See the sample code below.

Let us say, you have a Person like below.

CREATE TABLE [dbo].[Person]
(
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](128) NOT NULL,
	[Age] [int] NOT NULL,
	[CreatedDateUtc] [datetime2](5) NOT NULL,
	CONSTRAINT [CRIX_Person_Id] PRIMARY KEY CLUSTERED ([Id] ASC) ON [PRIMARY]
)
ON [PRIMARY];
GO

And a Customer table like below.

CREATE TABLE [dbo].[Customer]
(
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](128) NOT NULL,
	[Age] [int] NOT NULL,
	[CreatedDateUtc] [datetime2](5) NOT NULL,
	CONSTRAINT [CRIX_Customer_Id] PRIMARY KEY CLUSTERED ([Id] ASC) ON [PRIMARY]
)
ON [PRIMARY];
GO

Then, you create a class below.

public class PersonOrCustomer
{
	public long Id { get; set; }
	public string Name { get; set; }
	public int Age { get; set; }
	public DateTime CreatedDateUtc { get; set; }
}

Query

You should be able to query it like below. See the code for the Person table.

var people = connection.Query<PersonOrCustomer>("Person");

And Customer table.

var people = connection.Query<PersonOrCustomer>("Customer");

Insert

You should be able to insert it like below. See the code for the Person table.

var people = connection.Insert("Person", new PersonOrCustomer { Name = "John Doe" });

And Customer table.

var people = connection.Insert("Customer", new PersonOrCustomer { Name = "James Smith" });

Merge

You should be able to merge it like below. See the code for the Person table.

var people = connection.Merge("Person", new PersonOrCustomer { Id = 10045, Name = "James Doe" });

And Customer table.

var people = connection.Merge("Customer", new PersonOrCustomer { Id = 11011, Name = "John Smith" });

Update

You should be able to merge it like below. See the code for the Person table.

var people = connection.Update("Person", new PersonOrCustomer { Id = 10045, Address = "New York" });

And Customer table.

var people = connection.Update("Customer", new PersonOrCustomer { Id = 11011, Address = "New York" });

Extent (EDIT)

The extent of the changes must be on all operations available in RepoDb library.

Metadata

Metadata

Assignees

Labels

deployedFeature or bug is deployed at the current releaseenhancementNew feature or requestfeatureDefined as a big development item (feature)fixedThe bug, issue, incident has been fixed.priorityTop priority feature or things to dorequestA request from the community.todoThings to be done in the future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions