Skip to content

Bug: Table Attribute Potential Bug #464

@mikependon

Description

@mikependon

This issue needs a validation from the community - if this is really a big case or not. The priority will vary on the community request.

The Table attribute of System.ComponentModel.DataAnnotations.Schema is expecting the Table("TableName"), but there is a possibility the the Schema property may had been set explicitly. In RepoDb, this attribute is seems to be used as Table("[Schema].[TableName]") and defaultly ignoring the Schema property, like the existing Map("[Schema].[TableName]").

Here is the link to the code that could have the potential bug.

I would suggest to write it this way.

internal static string GetMappedName(Type type)
{
	return type.GetCustomAttribute<MapAttribute>()?.Name ??
		   GetMappedName(type.GetCustomAttribute<TableAttribute>()) ??
		   ClassMapper.Get(type) ??
		   type.Name;
}

With a helper method like below.

private static string GetMappedName(Table tableAttribute)
{
	if (tableAttribute == null)
	{
		return null;
	}
	if (string.IsNullOrEmpty(tableAttribute.Schema))
	{
		return tableAttribute.Name;
	}
	return $"[{tableAttribute.Schema}].[{tableAttribute.Name}]";
}

Important Note: We need to bring the IDbSetting object and use the ClosingQuote and OpeningQuote property to quote the values.

Acceptance Criteria: Make sure that all the existing Unit Tests and Integration Tests of all Solutions are passing (i.e.: RepoDb.Core, RepoDb.SqlLite, RepoDb.SqlServer, RepoDb.PostgreSql, RepoDb.MySql, RepoDb.MySqlConnector and RepoDb.SqlServer.BulkOperations).

Metadata

Metadata

Assignees

Labels

deployedFeature or bug is deployed at the current releasefixedThe bug, issue, incident has been fixed.known-bugA known-bug that has been a part of the release.todoThings to be done in the future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions