Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Collection Name Programmatically without static CollectionAttribute #222

Closed
LucaZiegler opened this issue Apr 20, 2024 · 1 comment
Closed
Labels
question further information is requested

Comments

@LucaZiegler
Copy link

Is it possible to set the Collection attribute dynamically when I want to save an entity?

Something like that:

var data = new FormData();
data.SetCollectionName("FormData_1");
await data.SaveAsync();

Instead of a fixed Collection attribute:

[Collection("FormData_1")]
public class FormData : Entity, ICreatedOn, IModifiedOn
{
@dj-nitehawk
Copy link
Owner

no such feature exists in this library but you can always drop down into the mongo driver level like so:

await DB.Database("dbName") //shortcut for obtaining the IMongoDatabase
        .GetCollection<FormData>("FormData_1")
        .InsertOneAsync(new FormData(){});

@dj-nitehawk dj-nitehawk added the question further information is requested label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants