Failing Build - EntityPatch does not exist

I am trying Radzen out and have been unable to successfully run a simple application I created, pointing it to an existing SQL database. For every table I included in the data source, it has the following line in the output:

Controllers\Marketing Test\CustomersController.cs(100,9): error CS0103: The name 'EntityPatch' does not exist in the current context [C:\Users\cperry\Documents\Radzen Apps\server\project.csproj]

Then it will fail:

The build failed. Please fix the build errors and run again.

I am at a loss as I am guessing that and Entity Patch is something Radzen using internally in the construction of the entities from the database tables.

Hi @cperry,

This is a very strange error. Radzen is supposed to generate that file in the server\Data directory. Here is how it is supposed to look like:

The EntityPatch class is supposed to be in the .Data namespace which is imported in every controller. Could you zip the server directory and attach it here so we can take a look?

It will not let me upload a file because I am a new user.

@cperry yes, the forum software we use does that. Let’s try something else then.

  1. Is there an EntityPatch.cs file in the server\Data directory?
  2. Can you paste the contents of the CustomersController.cs file?

There is a EntityPatch.cs file in the server\Data directory.

Here is the content of the CustomersController.cs file:

using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData;
using Microsoft.AspNetCore.OData.Routing;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Sm.Models;
using Sm.Data;
using Sm.Models.SmTest;

namespace Sm.Controllers.SmTest
{
  [EnableQuery]
  [ODataRoute("odata/SmTest/Customers")]
  public partial class CustomersController : Controller
  {
    private SmTestContext context;

    public CustomersController(SmTestContext context)
    {
      this.context = context;
    }
    // GET /odata/SmTest/Customers
    [HttpGet]
    public IEnumerable<Customer> Get()
    {
      var items = this.context.Customers.AsQueryable<Customer>();

      this.OnCustomersRead(ref items);

      return items;
    }

    partial void OnCustomersRead(ref IQueryable<Customer> items);

    [HttpGet("{Customer_ID}")]
    public IActionResult GetCustomer(int? key)
    {
        var item = this.context.Customers.Where(i=>i.Customer_ID == key).SingleOrDefault();

        if (item == null)
        {
            return NotFound();
        }

        return new ObjectResult(item);
    }
    partial void OnCustomerDeleted(Customer item);

    [HttpDelete("{Customer_ID}")]
    public IActionResult DeleteCustomer(int? key)
    {
        var item = this.context.Customers
            .Where(i => i.Customer_ID == key)
            .Include(i => i.Parts)
            .SingleOrDefault();

        if (item == null)
        {
            return NotFound();
        }

        this.OnCustomerDeleted(item);
        this.context.Customers.Remove(item);
        this.context.SaveChanges();

        return new NoContentResult();
    }

    partial void OnCustomerUpdated(Customer item);

    [HttpPut("{Customer_ID}")]
    public IActionResult PutCustomer(int? key, [FromBody]Customer newItem)
    {
        if (newItem == null || newItem.Customer_ID != key)
        {
            return BadRequest();
        }

        this.OnCustomerUpdated(newItem);
        this.context.Customers.Update(newItem);
        this.context.SaveChanges();

        return new NoContentResult();
    }

    [HttpPatch("{Customer_ID}")]
    public IActionResult PatchCustomer(int? key, [FromBody]JObject patch)
    {
        var item = this.context.Customers.Where(i=>i.Customer_ID == key).FirstOrDefault();

        if (item == null)
        {
            return BadRequest();
        }

        EntityPatch.Apply(item, patch);

        this.OnCustomerUpdated(item);
        this.context.Customers.Update(item);
        this.context.SaveChanges();

        return new NoContentResult();
    }

    partial void OnCustomerCreated(Customer item);

    [HttpPost]
    public IActionResult Post([FromBody] Customer item)
    {
        if (item == null)
        {
            return BadRequest();
        }

        this.OnCustomerCreated(item);
        this.context.Customers.Add(item);
        this.context.SaveChanges();

        return Created($"odata/SmTest/Customers/{item.Customer_ID}", item);
    }
  }
}

Thanks @cperry. Everything looks correct: there is an EntityPatch file and the controller imports the namespace it is in. Could you send the server directory over email to info@radzen.com?

Thank you for sending me the files @cperry.

It looks as if the same directory was used to create two different Radzen applications. Is that correct?

In any case deleting the server directory should solve the problem. Radzen will regenerate it and there would be no more compilation errors.

That worked. Thank you. When creating projects, I was in the Visual Studio mindset where I specify the parent folder and it creates a folder for me.