LiteDB icon indicating copy to clipboard operation
LiteDB copied to clipboard

How to insert dynamic ExpandoObject List

Open vickyRathee opened this issue 6 years ago • 6 comments

How to insert dynamic / ExpendoObject to LiteDb. The BsonMapper throw an Null exception Object reference not set to an instance of an object.

        dynamic myObj = new ExpandoObject();

	myObj.Test = "Yes";
	myObj.Value = 123;
	
	List<dynamic> list = new List<dynamic>();
	list.Add(myObj);
	
	var dynamicList = list.Select(s => BsonMapper.Global.ToDocument(s)).ToList();
	
	BulkInsertToLite(dynamicList);

vickyRathee avatar Jan 04 '19 12:01 vickyRathee

@mbdavid Does dynamic types supported in v5 ?

vickyRathee avatar Oct 26 '20 03:10 vickyRathee

@vickyrathee dynamic variables should work fine with LiteDB v5. The mapper uses reflection to detect the runtime type of the object.

lbnascimento avatar Oct 30 '20 16:10 lbnascimento

@lbnascimento Any example in docs or tests I can refer?

vickyRathee avatar Oct 31 '20 05:10 vickyRathee

It does not work with LiteDB v 5.0.10 It casts the same exception on Insert method: Null exception Object reference not set to an instance of an object.

mchudinov avatar Jan 18 '21 22:01 mchudinov

I am also experiencing the same issue. When I insert some dynamic values they are null

Irvinaby avatar Oct 14 '21 14:10 Irvinaby

Any updates on this topic? 5.0.11 seems to throw the same error.

haggerty-william avatar May 09 '22 16:05 haggerty-william