Base solution for your next web application
Open Closed

Problem Extending Non-Abstract Entities #3446


User avatar
0
kwanp created

Hi this link is very helpful: <a class="postlink" href="https://www.aspnetzero.com/Documents/Extending-Existing-Entities#extending-non-abstract-entities">https://www.aspnetzero.com/Documents/Ex ... t-entities</a>

but i have the problem when extending AbpOrganizationUnits table

public class OrgChartExtend : OrganizationUnit
    {
        public virtual string DisplayCode { get; set; }
    }
public partial class Added_DisplayCode_To_OrganizationUnit : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {

            migrationBuilder.AddColumn< string > (name: "DisplayCode", table: "dbo.AbpOrganizationUnits", nullable: true, maxLength: 50);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(name: "DisplayCode", table: "dbo.AbpOrganizationUnits");
        }
    }

and when i update this to the database error show this

PM> Update-Database
Executed DbCommand (35ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Applying migration '20170625042330_Added_DisplayCode_To_OrganizationUnit'.
Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE [dbo.AbpOrganizationUnits] ADD [DisplayCode] nvarchar(50);
System.Data.SqlClient.SqlException (0x80131904): Cannot find the object "dbo.AbpOrganizationUnits" because it does not exist or you do not have permissions.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean closeConnection)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.&lt;&gt;c__DisplayClass0_1.&lt;.ctor&gt;b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:74ac8c62-7c3f-4b38-9db1-246f2ccfc65f
Error Number:4902,State:1,Class:16
Cannot find the object "dbo.AbpOrganizationUnits" because it does not exist or you do not have permissions.

Thank you

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This is very strange. Can you check that if AbpOrganizationUnits table really exists on your DB or not ? Maybe it is deleted manually, is that possible ?

    Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    kwanp created

    Hi i got work for create DisplayCode Field to the DB.

    i also update

    OrganizationUnitDto.cs Class

    [AutoMapFrom(typeof(OrganizationUnit))]
        public class OrganizationUnitDto : AuditedEntityDto<long>
        {
            public long? ParentId { get; set; }
    
            public string Code { get; set; }
    
            public string DisplayName { get; set; }
    
            public int MemberCount { get; set; }
    
            public string DisplayCode { get; set; }
        }
    

    then run nswag/refresh.bat file and also modify the angular side to display DisplayCode Field but when i run the page DisplayCode Field is empty

    i also check the service-proxies.ts file DisplayCode also show

    xport class OrganizationUnitDto { 
        parentId: number; 
        code: string; 
        displayName: string; 
        memberCount: number; 
        displayCode: string; 
        lastModificationTime: moment.Moment; 
        lastModifierUserId: number; 
        creationTime: moment.Moment; 
        creatorUserId: number; 
        id: number;
        constructor(data?: any) {
            if (data !== undefined) {
                this.parentId = data["parentId"] !== undefined ? data["parentId"] : null;
                this.code = data["code"] !== undefined ? data["code"] : null;
                this.displayName = data["displayName"] !== undefined ? data["displayName"] : null;
                this.memberCount = data["memberCount"] !== undefined ? data["memberCount"] : null;
                this.displayCode = data["displayCode"] !== undefined ? data["displayCode"] : null;
                this.lastModificationTime = data["lastModificationTime"] ? moment(data["lastModificationTime"].toString()) : null;
                this.lastModifierUserId = data["lastModifierUserId"] !== undefined ? data["lastModifierUserId"] : null;
                this.creationTime = data["creationTime"] ? moment(data["creationTime"].toString()) : null;
                this.creatorUserId = data["creatorUserId"] !== undefined ? data["creatorUserId"] : null;
                this.id = data["id"] !== undefined ? data["id"] : null;
            }
        }
    

    How can i solve this issue Thank you

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you change your AutoMapFrom attribute like this:

    [AutoMapFrom(typeof(OrganizationUnit), typeof(OrgChartExtend))]
    

    If you added DisplayCode field to database manually, it will create other problems in the future. If you did it manually, maybe we should fix it first.

    Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    kwanp created

    How can i extend

    public class OrganizationUnit : FullAuditedEntity<long>, IMayHaveTenant
    {
      public OrganizationUnit(int? tenantId, string displayName, long? parentId = default(long?));
    }
    

    constructor to include my DisplayCode filed to be able to call , insert and update to the database

    and i also add this to the code but noting happen

    [AutoMapFrom(typeof(OrganizationUnit), typeof(OrgChartExtendCode))]
        public class OrganizationUnitDto : AuditedEntityDto<long>
        {
            public long? ParentId { get; set; }
    
            public string Code { get; set; }
    
            public string DisplayName { get; set; }
    
            public int MemberCount { get; set; }
    
            public string DisplayCode { get; set; }
        }
    

    Thank you

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    alper created
    Support Team

    hi

    I guess your connection string is different. Check that migration is being applied to the same database connection string

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    kwanp created

    My version is: ASP.NET CORE + ANGULAR 4.X i already check my connection string is the same because i try to create new table and its work

    can you please give me the sample on how to extend OrganizationUnit class to be able to Read,Insert, Update , and delete

    i just to add one more filed public string DisplayCode { get; set; }

    Thank you

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @kwanp,

    We have send you an email. If you can share your project with us, we will take a look at your problem.

    Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)