CRM tutorial


#1

In working through the RadZen CRM tutorial I have come up to an error I cannot seem to sort out. It does not seem to see the OnModelBuilding which is in the CrmContext file. I have verified the code against the GitHub sample and against the instructions. I get no help from VS. What have I done wrong? Anyone have a suggestion?


#2

What is the actual error message from the compiler? Here is how this should normally look like.


#3

This is the compiler error message.

dotnet: Data\CrmContext.Custom.cs(16,22): error CS0759: No defining declaration found for implementing declaration of partial method 'CrmContext.OnModelBuilding(ModelBuilder)' [D:\jkwrp\Documents\RadZen\RadZenCRM\server\project.csproj]

dotnet:


#4

This is part of the CrmContext.cs file. I did not include the properties:

using Microsoft.EntityFrameworkCore;
namespace RadZenCrm.Data
{
public partial class CrmContext : Microsoft.EntityFrameworkCore.DbContext
{
public CrmContext(DbContextOptions options):base(options)
{
}
public CrmContext()
{
}

partial void OnModelBuilding(ModelBuilder builder);

protected override void OnModelCreating(ModelBuilder builder)
{
    base.OnModelCreating(builder);

    builder.Entity<RadZenCrm.Models.Crm.Opportunity>()
          .HasOne(i => i.Contact)
          .WithMany(i => i.Opportunities)
          .HasForeignKey(i => i.ContactId)
          .HasPrincipalKey(i => i.Id);
    builder.Entity<RadZenCrm.Models.Crm.Opportunity>()
          .HasOne(i => i.OpportunityStatus)
          .WithMany(i => i.Opportunities)
          .HasForeignKey(i => i.StatusId)
          .HasPrincipalKey(i => i.Id);
    builder.Entity<RadZenCrm.Models.Crm.Task>()
          .HasOne(i => i.Opportunity)
          .WithMany(i => i.Tasks)
          .HasForeignKey(i => i.OpportunityId)
          .HasPrincipalKey(i => i.Id);
    builder.Entity<RadZenCrm.Models.Crm.Task>()
          .HasOne(i => i.TaskType)
          .WithMany(i => i.Tasks)
          .HasForeignKey(i => i.TypeId)
          .HasPrincipalKey(i => i.Id);
    builder.Entity<RadZenCrm.Models.Crm.Task>()
          .HasOne(i => i.TaskStatus)
          .WithMany(i => i.Tasks)
          .HasForeignKey(i => i.StatusId)
          .HasPrincipalKey(i => i.Id);

    this.OnModelBuilding(builder);
}

#5

Your namespace in the generated class is RadZenCrm whereas the demo relies on RadzenCrm - the casing is different hence the problem. Change the namespace in CrmContext.Custom.cs to the one of your application - RadZenCrm.Data:

namespace RadZenCrm.Data
{
    public partial class CrmContext
    {
    } 
}

#6

Thanks, I missed that entirely. I knew I should have done this in VB