You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wondering if it is possible to achieve next case
My entity has backing field of owned type. The owned type has navigation property to another entity
Product (entity)
|_ _productTitle (backing field, owned type)
| |_ _.Value (navigation property)
| |_ _ Value (Property)
|
|_ _Title => _productTitle.Value.Value; // It is ugly, I know. Sorry for naming
The idea (main goal) is to incapsulate logic of Title property inheritance (Product title can be inherited from title of parent node in product tree) inside of Product entity. And also that Title property of Product would be allowed to be used in linq query.
Some code
// Product entity
public abstract class ProductTreeSpecificationBased: Entity<Guid>
{
private Title _title { get; set; } // backing field of owned type
public string Title => _title.Value.Value; // property which is used by product consumer and in queries
}
// Title owned type
public class Title: ValueObject, IInheritedProperty
{
public ProductTitle Value { get; private set; }
public bool IsInherited { get; private set; }
public Title(ProductTitle value, bool iIsInherited = false)
{
Value = value;
IsInherited = isInherited;
}
}
// Product Title entity
public class ProductTitle : Entity<Guid>
{
[Required]
public string Value { get; private set; }
public ProductTitle(Guid id, string value)
{
Id = id;
SetValue(value);
}
}
I know/guess that I can use backing fields of owned type. It can be achieved via
.OwnsOne(typeof(Title), "_productTitle", x =>
{
x.Property("Value")
**// how to specify navigation?**
}) // **is it correct way?**
How further to configure model to achieve the main goal?
I know about #6674. I found the example about Samurai, but I do not really understand how that works and example was provided in 2017, but actually issue was closed by milestone 5.0.0, which was released on previous year.
The text was updated successfully, but these errors were encountered:
As you said, the real problem is not using field-only navigation properties(or 'backing fields').
And also that Title property of Product would be allowed to be used in linq query.
This is not supported, because Title property of Product entity is not mapped to an actual database column. Even worse, using Product.Title in linq query may cause client evalution.
I am wondering if it is possible to achieve next case
My entity has backing field of owned type. The owned type has navigation property to another entity
The idea (main goal) is to incapsulate logic of Title property inheritance (Product title can be inherited from title of parent node in product tree) inside of Product entity. And also that Title property of Product would be allowed to be used in linq query.
Some code
I know about #6674. I found the example about Samurai, but I do not really understand how that works and example was provided in 2017, but actually issue was closed by milestone 5.0.0, which was released on previous year.
The text was updated successfully, but these errors were encountered: