Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "jonas452"

If every class inherits FullAuditedEntity you can make a new class that inherits FullAuditedEntity and overwrite the Id key field. Otherwise do it manually and map those keys by fluent api.

For existing classes like Users you must inherit that in a new class and again override the key field.

Do check that when you choose your PK as a guid that there is not a clustered index on your key. That would cause a performance hit.

It's generally considered a bad idea to always use a GUID as a primary key.

As one must continue it's development i have defined a navigation property on my model. Something i really didn't want to do.

modelBuilder.Entity<Person>().Property(p => p.PUserAccount_Id).IsOptional().HasColumnName("PUserAccount_Id");
modelBuilder.Entity<Person>().HasOptional(p => p.PUserAccount).WithMany().HasForeignKey(pers => pers.PUserAccount_Id);

But hey, what can you do... If someone finds a better solution for this in the future, i'd love to hear it.

@ ismcagdas - Thx for the link ;)

I spent a significant amount of time trying to solve that problem and could not find a solution. So the only way to make that work is to define the ID properties in your models.

I don't want to place a foreignkey on my model. breaks the seperate layer design. So besides that solution is there a work around ? a certain mapping i can do in fluent api?

Hi,

I'm running against a bug// error in my code i can't figure out.

I have two classes related to each other. Person and User(aspnetmodulezero class user) User is named PUserAccount in the class Person

public class Person : FullAuditedEntity,IMustHaveTenant
    {
        public const int MaxNameLength = 32;
        public const int MaxFirstnameLength = 32;
        public const int MaxEmailAddressLength = 255;

        public virtual int TenantId { get; set; }
        [Required]
        [MaxLength(MaxNameLength)]
        public virtual string Name { get; set; }
        [Required]
        [MaxLength(MaxFirstnameLength)]
        public virtual string FirstName { get; set; }
        public virtual string PhoneNr { get; set; }
        public virtual User **PUserAccount**{ get; set; }
        [Required]  
        [MaxLength(MaxEmailAddressLength)]      
        public virtual string Email { get; set; }

        public Person()
        {

        }       
    }

In a certain point in my application i let the admin user link a person to a User. A person can exist without a user. To achieve this i have created a domain service.

public class PersonManager : EmployeePlannerSPADomainServiceBase, IPersonManager
    {
        private readonly IRepository<Person> _personRepository;
        private readonly UserManager _userManager;
        private readonly RoleManager _roleManager;

        public PersonManager(IRepository<Person> personRepository, 
                             UserManager userManager,
                             RoleManager roleManager)
        {
            _personRepository = personRepository;
            _userManager = userManager;
            _roleManager = roleManager;
        }

        public Person GetById(int id)
        {
            return _personRepository.GetAll().Where(p => p.Id == id).FirstOrDefault();
        }

        public async Task CreateAsync(Person pers)
        {
            await _personRepository.InsertAsync(pers);
        }

        public async Task<User> CreateNewUserFromPersonAsync(Person p)
        {
            //Get standard role - Tenant id should get injected in this manager
            List<Role> roles = _roleManager.Roles.Where(r =>r.Name == StaticRoleNames.Tenants.User).ToList();
            if (roles.Count == 1)
            {
                User newU = new User()
                {
                    UserName = p.Email,
                    Name = p.Name,
                    Surname = p.FirstName,
                    EmailAddress = p.Email,                    
                    IsEmailConfirmed = false,
                    ShouldChangePasswordOnNextLogin = true,
                    IsActive = false
                };
                await _userManager.CreateAsync(newU, "123qwe");                

                await UpdateAsync(p);

                return p.PUserAccount = newU;
            }
            else
            {
                throw new ApplicationException("No suitable standard role found for new user ");
            }            
        }

        public async Task DeleteByIdAsync(int Id)
        {            
            await _personRepository.DeleteAsync(Id);
        }

        public async Task LinkPersonToUserAsync(Person p, User u)
        {
            //Check if user has been linked before
            var lPers = _personRepository.GetAll().Where(
                    per => per.PUserAccount != null &&
                           per.PUserAccount.Id == u.Id                    
                ).ToList();
            
            if (lPers.IsNullOrEmpty())
            {
                p.PUserAccount = u;
                await UpdateAsync(p);
            }
            else
            {
                throw new ApplicationException("That user account is already linked to an other person");
            }            
        }

        public async Task UpdateAsync(Person pers)
        {
            await _personRepository.UpdateAsync(pers);
        }
    }

In my domain service you see a method LinkPersonToUserAsync. When executed i receive a exception on following line

per => per.PUserAccount != null &&
                           per.PUserAccount.Id == u.Id

The error : ERROR 2016-12-01 21:34:07,433 [6 ] nHandling.AbpApiExceptionFilterAttribute - An error occurred while preparing the command definition. See the inner exception for details. System.Data.Entity.Core.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.ApplicationException: FK Constriant not found for association 'EmployeePlannerSPA.EntityFramework.Person_PUserAccount' - must directly specify foreign keys on model to be able to apply this filter at EntityFramework.DynamicFilters.DynamicFilterQueryVisitorCSpace.Visit(DbPropertyExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbPropertyExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbPropertyExpression expression) at EntityFramework.DynamicFilters.DynamicFilterQueryVisitorCSpace.Visit(DbPropertyExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbPropertyExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitBinary(DbBinaryExpression expression, Func3 callback) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbComparisonExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbComparisonExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbFilterExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbFilterExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpression(DbExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBinding(DbExpressionBinding binding) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.VisitExpressionBindingEnterScope(DbExpressionBinding binding) at System.Data.Entity.Core.Common.CommandTrees.DefaultExpressionVisitor.Visit(DbProjectExpression expression) at System.Data.Entity.Core.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor1 visitor) at EntityFramework.DynamicFilters.DynamicFilterInterceptor.TreeCreated(DbCommandTreeInterceptionContext interceptionContext)

I'm not an expert on Entity framework but any help to filter on a foreign key for independent association would be appreciated. I really don't want to create a mapping with fluent mapi and define my own constraint(or create navigation properties in my poco). I have checked the database and the constraint has been autmaticaly created by EF

Currently i'm on version aspnetzero : v1.13.0.0

Thanks, Jonas

your image link is down.

Haven't posted my app to azure(i'm going to) but since tenant creation is fully managed by your app code it shouldn't fail. Does every new tenant gets it's own database? if so i would assume your problem lies with creating new databases.

lol, i did not know that was a search button. thx!

Yeah! It really is.

Thx!

Hi,

I have decided i will develop my aspnetzero application with angular. Now looking at the current road map i see that implementing angular2 is on the list.

I was wondering when the next version of aspnetzero with angular2 will be released. If the release date is near the end of 2017 then i'll focus my efforts on angular1 and find a way to upgrade to angular2 (i heard it wont be easy) But if the release date is in the near future i may be able to delay my develoment and start on the front end when it's released. I prefer the second option.

So a rough eta would be much appreciated.

Thx! Jonas

Showing 21 to 28 of 28 entries