Symptom

After upgrading to PB 2019 R2 Beta, the way to parse the loaded DataWindow has changed. If the user does not regenerate the Model corresponding to the DataWindow, the user will see the exception message such as "No metadata for DataWindow ‘XXX’ found” when instantiating a .NET DataStore.

Environment

  • PB 2019 R2 beta or above

Cause

When instantiating a DataStore in 2019 R2 beta, it is no longer based on the .srd file and its model class. It will be only based on a model class that has a DataWindowAttribute, such as [DataWindow("ds_task", DwStyle.Grid)].

Resolution

Follow the steps below to resolve this issue:

1. Regenerate the models

Please regenerate ds_task in SnapDevelop and see if it resolves the issue:

Solution Explorer -> right click on your solution -> select Open PB Workspace -> find "ds_task" -> right click -> Convert DataWindow to C# Model.

2. Check the code where DataWindows are parsed

In a ASP.NET Core Web API project, when app.UseDataWindow() is called in startup.cs, it will parse all of these models.

In other non-ASP.NET Core projects (e.g.: Console, Class Library, XUnit projects), we have to use anther solution.

Users need to create a new class (e.g.: PbUnitTestHost) inherited from the abstract class DWNet.Data.DataStoreHost.

When initiating the class PbUnitTestHost (e.g.: var host = new PbUnitTestHost();), the constructor of DWNet.Data.DataStoreHost will load and parse all of these models.

We can also inject dependencies in this PbUnitTestHost class.

Sample Code:

using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using SnapObjects.Data;
using SnapObjects.Data.SqlServer;
using DWNet.Data;
using WebApplication1;
using WebApplication1.Services;
using Microsoft.Extensions.Configuration;
namespace XUnitTestProject1
{
    public class PbUnitTestHost : DataStoreHost
    {
        protected override IServiceCollection ConfigureServices(IServiceCollection services)
        {
            // Build Configuration
            var configuration = new ConfigurationBuilder()
                .AddJsonFile("testsettings.json")
                .Build();
            // Microsoft SqlServer
            string connectionString = configuration["ConnectionStrings:AdventureWorks"];
            services.AddDataContext<DefaultDataContext>(m => m.UseSqlServer(connectionString));
            // Inject a service
            services.AddScoped(typeof(ISampleService), typeof(SampleService));
            return base.ConfigureServices(services);
        }
        protected override void Configure(IServiceProvider serviceProvider)
        {
            base.Configure(serviceProvider);
        }
    }
}

More Information

This KB is subject to change as we are still on a beta version as of this writing.

6
2