diff --git a/src/CoreTests/DocumentSchemaResolverTests.cs b/src/CoreTests/DocumentSchemaResolverTests.cs index e17dac26ae..e83dfb643c 100644 --- a/src/CoreTests/DocumentSchemaResolverTests.cs +++ b/src/CoreTests/DocumentSchemaResolverTests.cs @@ -72,7 +72,7 @@ public void ValidateRegisteredDocumentNames() var schema = theSession.DocumentStore.Options.Schema; - schema.For().ShouldBe("documentschemaresolvertests.mt_doc_account"); + schema.For(typeof(Account)).ShouldBe("documentschemaresolvertests.mt_doc_account"); schema.For().ShouldBe("documentschemaresolvertests.mt_doc_company"); schema.For().ShouldBe("documentschemaresolvertests.mt_doc_user"); diff --git a/src/Marten/IDocumentSchemaResolver.cs b/src/Marten/IDocumentSchemaResolver.cs index a48e2b9879..cd0883288a 100644 --- a/src/Marten/IDocumentSchemaResolver.cs +++ b/src/Marten/IDocumentSchemaResolver.cs @@ -1,4 +1,6 @@ #nullable enable +using System; + namespace Marten; public interface IDocumentSchemaResolver @@ -25,6 +27,17 @@ public interface IDocumentSchemaResolver /// The name of in the database. string For(bool qualified = true); + /// + /// Find the database name of the table backing . Supports documents and projections. + /// + /// The document type + /// + /// When true (default) the qualified name is returned (schema and table name). + /// Otherwise only the table name is returned. + /// + /// The name of in the database. + string For(Type documentType, bool qualified = true); + /// /// Find the database name of the table backing the events table. Supports documents and projections. /// diff --git a/src/Marten/StoreOptions.cs b/src/Marten/StoreOptions.cs index 08e747193a..70cb02ee2a 100644 --- a/src/Marten/StoreOptions.cs +++ b/src/Marten/StoreOptions.cs @@ -896,6 +896,12 @@ string IDocumentSchemaResolver.For(bool qualified) return qualified ? docType.TableName.QualifiedName : docType.TableName.Name; } + public string For(Type documentType, bool qualified = true) + { + var docType = ((IReadOnlyStoreOptions)this).FindOrResolveDocumentType(documentType); + return qualified ? docType.TableName.QualifiedName : docType.TableName.Name; + } + string IDocumentSchemaResolver.ForEvents(bool qualified) { return qualified ? _eventGraph.Table.QualifiedName : _eventGraph.Table.Name;