Are there any plans to support Guid, Decimal, and Enums? Currently we're getting around Guid and Decimal by storing them as strings. and Enums by storing them as int, but having them supported would make the class more well defined.
What kind of queries would you want to run on these types?
We have ongoing discussions across the different teams of additional data types to support. As Realm is a multi-platform engine with support in many languages, we aim to provide uniform support of types.
Storing as a byte array would be more efficient for GUID and Decimal, if you only want to do equality searches. You can see an example of binary searches in SearchComparingByteArrays in SimpleLINQtests.cs. If you need sorting or comparative searches, storing as formatted strings is unfortunately your only option for now.
for Guid, i think just equality checking is ok. For decimal it'd be nice to be able to do comparative searches.
I think Guid is important if you use UUID's as the "ObjectId or primary key", however you want to call it. And decimal is important if you're working with currency.
It doesn't really matter so much how Realm stores it internally if you can define the classes like so. It adds alot more clarity to what the type is supposed to be:
public class Item : RealmObject
{
public Guid ItemId { get; set; }
public decimal Price { get; set; }
}
currently you'd have to hack it like so:
public class Item : RealmObject
{
public string Itemid { get; set; }
public string Price { get; set; }
}
or wrap it in another property:
public class Item : RealmObject
{
//make sure to query using stored item id instead
public string StoredItemId { get; set; }
public Guid ItemId get { return new Guid(StoredItemid); } set { StoredItemId = value.ToString() }
//make sure to query using stored price instead
public string Price { get; set; }
public decimal Price { get { return Decimal.Parse(StoredPrice); } set { StoredPrice = value.ToString(CurrentCulture.InvariantCulture); }
}
Hi, any news?
Are there any plans to support these?
We don't have immediate plans to support those. There is an easy workaround for guids and enums, and while we would like to get native decimal support, we have quite a few financial institutions as customers and they have not requested it, so barring a paid contract, it's unlikely it'll land before 2019.
@nirinchev what鈥檚 the workaround for enums?
@karlingen off the top of my head it should be something like this:
enum Color : int
{
Red,
Green,
Blue
}
class Item : RealmObject
{
private int Color_raw { get; set; }
public Color Color
{
get { return (Color)Color_raw; }
set { Color_raw = (int)value; }
}
}
Yes - alternatively, you can store the raw value as a string if you prefer the readability (e.g. if you open the Realm in studio) or if you are worried about someone reordering the values accidentally.
@fealebenpae @nirinchev
Thanks to both of you!
I did this:
```c#
public enum Color
{
Undefined,
Red,
Blue
}
class Item : RealmObject
{
private string ColorRaw { get; set; }
public Color Color
{
get { return Enum.TryParse(ColorRaw, out Color result) ? result : Color.Undefined; }
set { ColorRaw = value.ToString(); }
}
}
```
Guid doesn't have a good workaround at the moment, since Realm doesn't allow byte[] as a PrimaryKey or Index property. So you have to store as a string, i.e. using even more storage than necessary for a datatype that is already very large.
Having good support for byte[] would fix this: there is no reason that byte[] shouldn't support all the functionality that string does.
Decimals are already supported and support for Guids was implemented recently, so the only item on this list left is supporting Enums. This is covered by https://github.com/realm/realm-dotnet/issues/549, so I'll close this issue.
Very happy to have Guid support in! Weirdly, I'm getting this fody error (Realm 10.0.0-beta3):

Is this an oversight or am I doing something incorrectly?
Support for Guids was merged but hasn't been released yet.
Right, thanks (thought it may have been due to the PR being merged before the recent beta release).
Will this be in the next beta release per chance?
It will happen to work, but not be officially supported. We expect to announce official support for it later this quarter.