CRM tutorial

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?

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

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:

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);
}

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
    {
    } 
}

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

I am receiving the same error, and have checked the spelling.

Same issue with me
Pleas Guide

Same issue error with me

Stick with it. I thought the same as you but Iā€™m over the hump of the learning curve and the examples and support for c# are a 100 x more than vb. Iā€™m sure lots of folk may disagree but Iā€™m very glad I bit the bullet and learnt c#.

1 Like