Hi,
When you say "it works perfectly" what do you mean? When I did exactly that, the Customer Entity didn't have a Address collection navigation property and it appeared to create a 1-1 relationship in CustomerWithNaviagtionProperties class. See below. That's not 1 Customer with Many addresses.
Your screenshots just illustrate the UI for creating Addresses. That's wasn't the question.
Further assistance would be appreciated. Thanks
Mat
public class Customer : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; set; }
[CanBeNull]
public virtual string Name { get; set; }
public Guid? AddressId { get; set; }
public Customer()
{
}
public Customer(Guid id, Guid? addressId, string name)
{
Id = id;
Check.Length(name, nameof(name), CustomerConsts.NameMaxLength, 0);
Name = name;
AddressId = addressId;
}
}
public class CustomerWithNavigationProperties
{
public Customer Customer { get; set; }
public Address Address { get; set; }
}
Hi,
NOTE: This is not an answer, just a follow-up question
Having gone through the free Implementing DDD pdf I see that the reason that navigation properties are not created is so as to remain database provider agnostic. I will only be using EF Core and SQL so this is not an issue for me. I note that the documentation says "If you think such features are important for you and you will never stray from the EF Core, we believe that it is worth stretching this principle."
Do you have any code samples that make use of entities with navigation properties? Normally I would just use AutoMapper to map the DTO to the entity and sub-entities, however is is not possible because the requirements use Guid as the identity. Is there anyway to get around this or a preferred method that doesn't involve setting every property manually. Something like:
CreateMap<AddressCreateDto, Address>().ConstructUsing(a => new Address(_guidGenerator.Create()));
An example of the type of entity relationships I'm trying to deal with would be as follows:
public class Customer
{
public Guid Id { get; set; }
public string Email { get; set; }
public object FirstName { get; set; }
public object LastName { get; set; }
public int CurrencyId { get; set; }
// Navigation Property
public List<Address> Addresses { get; set; }
// Navigation Property
public Currency Currency { get; set; }
}
public class Address
{
public Guid Id { get; set; }
public string Line1 { get; set; }
public string City { get; set; }
public string Zip { get; set; }
}
// Shared Reference Data
public class Currency
{
public int Id { get; set; }
public string Name { get; set; }
public string IsoCode { get; set; }
}
Any assistance or sample code would be very helpful.
Thanks
Mat
Hi,
Ok, I've been some more testing.
I'm calling CurrentTenant.Change() within an MVC page an it is correctly changing the TenantId.I am then calling the StoresAppService.CreateAsync();
If I check CurrentTenant.Id within the CreateAsync method it is null.
Any assistance would be appreciated.
Mat
Hi,
I'm calling CurrentTenant.Change(existingTenant.Id) within a using statement an attempting to save a new record that belongs to the tenant. Unfortunately, the resulting record in the DB has null in the tenantId. What am I missing?
// Change Tenant
using (CurrentTenant.Change(existingTenant.Id))
{
// Create New Store
var newStore = new StoreCreateDto
{
ExternalId = storeName,
Name = storeName,
Timezone = ecomStore.Timezone
};
await _storesAppService.CreateAsync(newStore);
}
// Simplified Store Entity Below
public class Store : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; set; }
[NotNull] public virtual string Name { get; set; }
[CanBeNull] public virtual string ExternalId { get; set; }
// Etc
}
Any assistance would be appreciate.
Also, while I'm on the topic of switching tenants, what's the best way to manually locate a tenant (in situations where you can't use a resolver) . Is there a better way than this. Using GetList with a filter seems a but clunky.
// 1. Load existing Tenant
var existingTenant = (await _tenantAppService.GetListAsync(new GetTenantsInput { Filter = name})).Items.SingleOrDefault();
Thanks
Mat
Hi,
I'm using Entity Framework with SQL Server and am having a few issues with the relationships and the entities generated by abp suite.
For instance, I'd like to create a one-to-many between customer and address where the customer can have multiple addresses. I'd expect to see the Customer entity have a Collection navigation property (as below), but abp suite appears to create a one-to-one relationship with the navigation property defined in CustomerWithNavigationProperties. hHen I review the documentation for AggregateRoot Class it suggests my expected entity structure is correct. What am I doing wrong / missing?
Similarly, I'd like to create a one-to-one relationship between Customer and a second table MarketingStatus. I'd expect to see a Reference navigation property added to Customer entity but I can't seem to achieve this either.
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Address> Addresses { get; set; }
public MarketingStatus MarketingStatus { get; set; }
}
Is this possible to achieve using entity generation using abp suite or do I need to defining these by hand. Can you assist?
Thanks
Mat