I currently just have my model hooked up to QueryDb. However, I was hoping to expand my model to include some calculated results.
The SqlServer FileTable model would look something like the following (using ServiceStack.OrmLite.SqlServer.Converters to include SqlHierarchyId support). Note that when a FileTable is created, the server defines the fields, so you can not add or rename fields (makes sense considering they are tied to the filesystem).
public class FileStream
{
[Alias(“stream_id”)]
public Guid ID { get; set; }
[Alias("file_stream")]
[Ignore()]
public byte[] FileContent { get; set; }
[Alias("name")]
[StringLength(255)]
public string Name { get; set; }
[PrimaryKey()]
[Alias("path_locator")]
public SqlHierarchyId Path { get; set; }
[ForeignKey(typeof(FileStream))]
[Alias("parent_path_locator")]
public SqlHierarchyId? ParentPath { get; set; }
[Alias("file_type")]
[Compute]
[StringLength(255)]
public string FileType { get; set; }
[Alias("cached_file_size")]
[Compute]
public long? FileSize { get; set; }
[Alias("creation_time")]
public DateTimeOffset CreationDateTime { get; set; }
[Alias("last_write_time")]
public DateTimeOffset LastWriteDateTime { get; set; }
[Alias("last_access_time")]
public DateTimeOffset? LastAccessDateTime { get; set; }
[Alias("is_directory")]
public bool IsDirectory { get; set; }
[Alias("is_offline")]
public bool IsOffline { get; set; }
[Alias("is_hidden")]
public bool IsHidden { get; set; }
[Alias("is_readonly")]
public bool IsReadOnly { get; set; }
[Alias("is_archive")]
public bool IsArchive { get; set; }
[Alias("is_system")]
public bool IsSystem { get; set; }
[Alias("is_temporary")]
public bool IsTemporary { get; set; }
}
Would love to include a property decorated with an attribute to return a computed result with AutoQuery.
Something like this:
[Expression(“file_stream.GetFileNamespacePath() + (CASE WHEN is_directory = 1 THEN '' ELSE ‘’ END)”)]
public string FullPath { get; set; }
Then, whenever a select statement is called that includes the new property, the expression would be injected instead of the field’s name. It should be ignored for all other operations.
SELECT
stream_id AS ID,
– file_stream AS FileContent, // ignored due to size (creates an OutOfMemoryException when included)
name AS Name,
path_locator AS Path,
parent_path_locator AS ParentPath,
file_type AS FileType,
cached_file_size AS FileSize,
creation_time AS CreationDateTime,
last_write_time AS LastWriteDateTime,
last_access_time AS LastAccessDateTime,
is_directory AS IsDirectory,
is_offline AS IsOffline,
is_hidden AS IsHidden,
is_readonly AS IsReadOnly,
is_archive AS IsArchive,
is_system AS IsSystem,
is_temporary AS IsTemporary,
file_stream.GetFileNamespacePath() + (CASE WHEN is_directory = 1 THEN '' ELSE ‘’ END) AS FilePath
FROM dbo.FileStream
There are some issues with this approach such as trying to use an aggregate function on a non-aggregate query – database would shed tears.
You probably have a much easier solution or better ideas on how to implement this. So I would love to hear your thoughts/recommendations.
Regards