Hi, I have extended User entity like below:
public class User : AbpUser<User>
{
public const int MaxPhoneNumberLength = 24;
.....
//Can add application specific user properties here
public MyCompanyName.AbpZeroTemplate.XXX.Address HomeAddress { get; set; }
by adding HomeAddress of class Address
Address class looks like this:
namespace MyCompanyName.AbpZeroTemplate.XXX
{
public class Address : ValueObject<Address>
{
public Country Country { get; set; } //A reference to a Country entity.
public string City { get; set; }
public string Street { get; set; }
public string PostalCode { get; set; }
public int? Number { get; set; }
public Address()
{
}
public Address(Country country, string city, string street, int? number, string postalCode)
{
Country = country;
City = city;
Street = street;
Number = number;
PostalCode = postalCode;
}
}
[Table("Countries")]
public class Country : FullAuditedEntity<int>, IMustHaveTenant
{
public int TenantId { get; set; }
/// <summary>
/// ISO 3166 Codes
/// </summary>
public virtual string CodeA2 { get; set; }
/// <summary>
/// ISO 3166 Codes
/// </summary>
public virtual string CodeA3 { get; set; }
public virtual string Name { get; set; }
public Country() { }
public Country(string codeA2, string codeA3, string name) { CodeA2 = codeA2; CodeA3 = codeA3; Name = name; }
}
}
Thanks to the upgrade to EFCore 2.0 we are able to use ValueObjects and thats great! It works, AbpUsers table is extended with HomeAddress_XYZ columns as per class structure above. It has HomeAddress_CountryId as the foreign id. all is good.
Problem comes when we edit an user, call to:
[AbpAuthorize(AppPermissions.Pages_Administration_Users_Create, AppPermissions.Pages_Administration_Users_Edit)]
public async Task<GetUserForEditOutput> GetUserForEdit(NullableIdDto<long> input)
{
...
//Editing an existing user
var user = await UserManager.GetUserByIdAsync(input.Id.Value);
// !!! HERE: user has HomeAddress set to an instance of Address, but HomeAddress.Country is null !!!
...
}
variable user has HomeAddress set to an instance of Address, but HomeAddress.Country is null !!!
Is it possible to do some kind of an include on Country class or something to let know the UserManager to extract country data?
thanks
It's working. Had to add some code into the DbContext in order for the migrator to recognize the complextype.
<cite>alper: </cite> Hi again,
Bad news! Entity Framework Core does not support complex types at the moment. Good news! It will be supported in 2.0.0 version. When it releases we will update the framework.
I am using EFCore 2.0 now and still not able to use ComplexTypes!!! Is there a specific way to use it?
are we using EF Core 2.0, yet? It has been released!
Hi, When can we expect the SignalR to work with ASPNET Core and Angular?
Hi, when can we expect to see version with EF Core 2.0 ?
Hi, trying to do ng build --prod and get the following error
this is version as per 30th june 2017 from dev branch
ERROR in C:/.../angular/src/$$_gendir/app/shared/layout/footer.component.ngfactory.ts (47,79): Property 'editionDisplayName' does not exist on type 'TenantLoginInfoDto'.
Hi, I made the merge with my development code and it seems to be working just fine thx
I am not adding it to DbContext!
My Address class: [ComplexType] public class Address : ValueObject<Address> { public Country Country { get; private set; } //A reference to a Country entity. public string City { get; private set; }
public string Street { get; private set; }
public string PostalCode { get; private set; }
public int Number { get; private set; }
public Address(Country country, string city, string street, int number, string postalCode)
{
Country = country;
City = city;
Street = street;
Number = number;
PostalCode = postalCode;
}
}
trying to add migration I get:
PM> Add-Migration "Add_Address"
System.InvalidOperationException: The entity type 'Address' requires a primary key to be defined.
at Microsoft.EntityFrameworkCore.Internal.ModelValidator.ShowError(String message)
at Microsoft.EntityFrameworkCore.Internal.ModelValidator.Validate(IModel model)
at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.Validate(IModel model)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func
2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.LazyRef1.get_Value() at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0
1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The entity type 'Address' requires a primary key to be defined.