Reputation: 4855
I have the following class:
[Keyless]
public class SimpleTimeSpan
{
public int Days { get; set; }
public int Hours { get; set; }
public int Minutes { get; set; }
}
which I'm using in an entity class like this:
public class MyEntity
{
public Guid Id { get; set; }
public string SomeProperty { get; set; }
public SimpleTimeStapn Cutoff { get; set; }
}
I'm using Cosmos db as database and am using package Microsoft.EntityFrameworkCore.Cosmos 5.0.x.
When saving to the database I expect an entity like this
{
"Id": "xxxx-yyyy-zzzz",
"SomeProperty": "my value",
"Cutoff": {
"Days": 1,
"Hours": 5,
"Minutes": 20
}
}
For this property I get this error:
InvalidOperationException: Unable to determine the relationship represented by navigation 'MyEntity.Cutoff' of type 'SimpleTimeSpan'
How do I map this property?
Upvotes: 0
Views: 302
Reputation: 4544
As @Danyliv mentioned in the comment section, using Owned
entity type allows you to model entity types that can only ever appear on navigation properties of other entity types. The entity containing an owned entity type is its owner.
Your class will look like this:
[Owned]
public class SimpleTimeSpan
{
public int Days { get; set; }
public int Hours { get; set; }
public int Minutes { get; set; }
}
Upvotes: 1