Including values onto the queried type #3050
-
I've been looking around the documentation and here on Github for a way to assign included values on the queried type, but I've yet to find anything concrete. So, I figured I'd ask whether it's possible. Imagine a 1:1 relationship - although I imagine it might function for 1:N or N:N - which are stored in seperate tables: public class Country
{
public Guid ID { get; set; }
public string Name { get; set; } = string.Empty;
public Guid CapitalCityID { get; set; }
[MartenIgnore]
public City Capital { get; set; } = default!;
} public class City
{
public Guid ID { get; set; }
public string Name { get; set; } = string.Empty;
public Guid CountryID { get; set; }
[MartenIgnore]
public Country Country { get; set; } = default!;
} Currently, if I wanted to include City into Country - or the other way around, for that matter - you'd have to make an extra variable to store it: City? city = null;
Country country = await querySession
.Query<Country>()
.Include<City>(c => c.CountryID, c => city = c)
.Single(c => c.Name == "Denmark");
country.City = city;
return country; I'm curious whether it's possible to turn into into something like this: Country country = await querySession
.Query<Country>()
.Include<City>(country => country.CapitalCityID, (country, city) => country.Capital = city)
.Single(v => v.Name == "Denmark"); so you can skip out on the extra variable entirely. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@maxnatamo And after all that, sorry, no. That's not something that's really ever come up. Marten -- and any other document db most likely -- is a lot more ideal when you don't have a lot of references between entity types. And |
Beta Was this translation helpful? Give feedback.
@maxnatamo And after all that, sorry, no. That's not something that's really ever come up. Marten -- and any other document db most likely -- is a lot more ideal when you don't have a lot of references between entity types. And
[MartenIgnore]
has no impact on serialization. You might be better off with an ORM approach like EF Core for this kind of usage