When two document types belongs to different schemas having same alias not allowed. Giving ambiguity error when accessed using IDocumentSession. #2948
Unanswered
maheshnicham123
asked this question in
Q&A
Replies: 1 comment 2 replies
-
See this: https://martendb.io/documents/storage.html#type-aliases |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Team,
I have scenario where 2 document types are having same alias(or classnames), but they belongs to different schemas like below -
[Same database]
First document type -:
[DatabaseSchemaName("public")]
public class MaterialEntity : BaseEntity
{
//Properties specific to this document goes here.
}
Second document type -:
[DatabaseSchemaName("manufacturing")]
public class MaterialEntity : AggregateBaseEntity
{
//Properties specific to this document goes here.
}
Trying to fetch first document type using it's repository below -:
public class MaterialRepository : IMaterialRepository
{
private readonly IDocumentSession _dbSession;
}
Similarly accessing second document type using it's specific repository.
Below marten library code is giving AmbiguousDocumentTypeAliasesException
[Using Marten 5.11.0 nuget]
private void assertNoDuplicateDocumentAliases()
{
var duplicates =
AllDocumentMappings.Where(x => !x.StructuralTyped)
.GroupBy(x => x.Alias)
.Where(x => x.Count() > 1)
.ToArray();
if (duplicates.Any())
{
var message = duplicates.Select(group =>
{
return
$"Document types {group.Select(x => x.DocumentType.FullName!).Join(", ")} all have the same document alias '{group.Key}'. You must explicitly make document type aliases to disambiguate the database schema objects";
}).Join("\n");
I know this issue can be fixed by changing the document type class name. But business is not allowing it because there will be more document types added with similar name in future.
Further I tried to group document types by there schema using below DI( It worked) but now I am unable to implement UoW using TransactionScope object (I am using Meidar library and there are nested calls to handler-pipeline-behavior)
//This dependency injection for creating documentsession/querysession specific to 'public' schema document types
builder.Services.AddMartenStore(opts =>
{
opts.Connection(dbConnectionString);
opts.DatabaseSchemaName = "public";
Is there any way to instruct marten to use fully qualified name of documenttype instead of alias only?
Please advise!
Beta Was this translation helpful? Give feedback.
All reactions