Hi, can anyone explain how ITypeNameBinder is used?
It's referenced here and something got merged but no documentation on it mbdavid/LiteDB#1108
I'm just wondering if that will help me.
I'm looking to override the default behaviour to be able to ignore documents with a _type where the assembly isn't loaded so it won't deserialise it. I've been looking at custom mappers but I can see how to use the default mapping once I've overridden the mapper for the base type as calling ToDocument and ToObject is a circular reference to the custom mapper (as is Serializer and Deserialize).
https://i.vgy.me/jBy3cn.png
How i can Include a property in array property of my entity?
I Have class Phrase with prop List<Option> and each option have prop Phrase, when i get a Phrase i need include all Phrase in Options.
Would you give this a try?
https://www.nuget.org/packages/LiteDB.Helper.IncludeAll/
Hello, I have this model
public class BookDetailedTypeModel : BaseLiteDBModel
{
public new static readonly string CollectionName = "book_detailed_types";
public int DetailedTypeID { get; set; }
public string DetailedTypeName { get; set; }
public int BooksCount { get; set; }
internal static void MappingInit()
{
BsonMapper.Global.Entity<BookDetailedTypeModel>()
.Ctor(/**/)
.Id(x => x.DetailedTypeID, true)
.Field(x => x.DetailedTypeName, "DetailedTypeName")
.Field(x => x.BooksCount, "BooksCount");
}
}
I want to know how I can use ctor in fluent mapping (BsonCtor).
Any help?
Best Regards
Second question: about DbRef
Here, I have this model
public class CategoryModel : BaseLiteDBModel
{
public new static readonly string CollectionName = "categories";
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public int? OrderNumber { get; set; }
public int BooksCount { get; set; }
public int? ParentCategoryID { get; set; }
public virtual CategoryModel ParentCategory { get; set; }
public CategoryModel()
{
}
[BsonCtor]
public CategoryModel(int categoryID, string categoryName, int? orderNumber, int booksCount, int? parentCategoryID, CategoryModel parentCategory)
{
CategoryID = categoryID;
CategoryName = categoryName;
OrderNumber = orderNumber;
BooksCount = booksCount;
ParentCategoryID = parentCategoryID;
ParentCategory = parentCategory;
}
internal static void MappingInit()
{
BsonMapper.Global.Entity<CategoryModel>()
//.Ctor(/**/)
.Id(x => x.CategoryID, true)
.Field(x => x.CategoryName, "CategoryName")
.Field(x => x.OrderNumber, "OrderNumber")
.Field(x => x.ParentCategoryID, "ParentCategoryID")
.Ignore(x => x.BooksCount)
.DbRef(x => x.ParentCategory);
}
}
and I did these insertions
Collection.Insert(new CategoryModel
{
CategoryName = "Category 1", // Auto id will be : 1
});
Collection.Insert(new CategoryModel
{
CategoryName = "Category 2",
});
Collection.Insert(new CategoryModel
{
CategoryName = "Category 3",
ParentCategoryID = 1,
});
then tried to retrieve them with include but ParentCategory is always null , what's wrong?
Collection.Include(x => x.ParentCategory).Query().ToList();
public
properties of your class to build up the collection, the only thing you need is the Mapper.
InsertBulk()
functionality provided.
SELECT COUNT($.Items) FROM Collection WHERE COUNT($.Items) > @Limit.
In C#, I believe this would be col.Find(X => X.Items.Count > limit);
Hello! I would like to select two field from my root document: RootProp and ChildProp (which is an array of objects), based on a condition:
SELECT $.RootProp, $.ChildProp[@.Name = 'ChildPropName'] FROM MyCollection WHERE COUNT($.ChildProp) > 0
My goal is to get only those results that have a populated ChildProp array (Where statement). However in the results I get also those records which do not contains any element on the ChildProp array. What am I missing? thanks
:point_up: Edit: Hello! I would like to select two field from my root document: RootProp and ChildProp (which is an array of objects), based on a condition:
SELECT $.RootProp, $.ChildProp[@.Name = 'ChildPropName'] FROM MyCollection WHERE COUNT($.ChildProp) > 0
My goal is to get only those results that have a populated ChildProp array (Where statement). However in the results I get also those records which do not contains any element on the ChildProp array. What am I missing? thanks
Hello! I need help in updating a list in my User table:
i have a Table called User. The User has a List with Devices.
Now i changed my Device assembly and namespace and now i need to change the Type (_type) of my Devices.
I tried so many approaches but nothing did work and im out of ideas. The last command i tried was:
'''UPDATE User SET Devices = Devices[]._type = 'DeviceSet.Mobile.Models.BleDevice, DeviceSet' ''' which gave me following Error:
Left expression `MAP($.Devices[]=>@._type)` returns more than one result. Try use ANY or ALL before operant.
I'm looking forward to any help!
Hello, I recently changed a field's data type from int to string.
After the changes, I'm getting "Casting Exception" when I try to read the records.
I did some reading and notice that I need to manage the new schema using DatabaseVersion. In order to change the schema, I need to perform the migration to the existing database. Is this the right way to do? Any other idea?
I went ahead to implement the migration to change the data type by resaving the BSONValue.
After that, I increment the database version to 1.
Now, how do I mark a newly created database to version 1 so it won't have to go through the migration (migration is meant for existing database).