This questions refers to the SisoDB - an SQL-Server-based document database written in C#.
I am trying to store a FileInfo entity to the database. In order to avoid (potential) circular references I define the interface for the fields I need:
interface IFileData
{
Guid Id { get; set; }
string DirectoryName { get; set; }
long Length { get; set; }
string Name { get; set; }
}
and then try to store a FileInfo entity:
var db = @"Data Source=C:\Temp\sisotest.sdf".CreateSqlCe4Db();
db.EnsureNewDatabase();
var info = new FileInfo(@"c:\config.sys");
db.UseOnceTo().InsertAs<IFileData>(info);
This results in StackOverflow exception. Any ideas why it is so and how can I overcome this problem?
SisoDb relies on the performant and outstanding serialization framework of ServiceStack.Text and my first test was to see if it can serialize a
FileInfo
, and that's where theStackOverFlowException
seems to be generated. You can try this by either usingSisoDb.Serialization
(which is a copy of ServiceStack.Text) or by using ServiceStack.Text directly.As of now
InsertAs<T>
requiresT
to be an interface.Insert<T>
andInsertMany<T>
can handle interfaces, but also requires the actual item to implement the interface.So as of now, to get further:
1) make a class out of
IFileData
.2) Normally that should have been ok, but since the
FileInfo
can't be serialized to JSON, you need to, either:a) Tell the ServiceStack serializer (contained in SisoDb.Serialization) not to include the properties causing the deserialization issue:
b) Or you can make
FileData
wrap aFileInfo
c) Or you can make a custom wrapper
FileInfo2
which wrapsFileInfo
.