dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
547 stars 70 forks source link

About Customize collection names #214

Closed goodnull closed 1 year ago

goodnull commented 1 year ago

Is there any other way besides using CollectionAttribute?

[Collection("Writer")]
public class Author : Entity
{
    ...
}

I now have multiple Collections, and their structures are the same. I don’t want to define multiple classes.

dj-nitehawk commented 1 year ago

even though mongodb itself doesn't enforce a schema, mongodb.entites does try to keep the developer disciplined by having 1 class per collection. this is by design and you're not supposed to store multiple classes/entity types in the same collection.

when you say I now have multiple Collections, do you mean the structure of the data is the same in those? if so, why not store all similar data structures/docs in the same collection?