До сих пор я использовал Breeze на .net framework. Работает отлично. Для нового проекта я хочу переключиться на .net core 3.0.100, чтобы написать бэкэнд-программное обеспечение, также называемое web api.
Так что я впервые настраиваю приложение .net core web api с breeze и EF,Настройка по https://github.com/Breeze/northwind-core-ng-demo
- .netcore 3.0.100
- Breeze .netcore
- Постоянная Breeze EFCore
- Структура сущностей SQLServer
При вызове метаданных () в persistencemanager выдается ошибка:
Message [string]:"Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.IProperty.get_ClrType()'."
Подробная ошибка:
Exception has occurred: CLR/System.MissingMethodException
An exception of type 'System.MissingMethodException' occurred in Breeze.Persistence.EFCore.dll but was not handled in user code: 'Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.IProperty.get_ClrType()'.'
at Breeze.Persistence.EFCore.MetadataBuilder.CreateDataProperty(IProperty p)
at Breeze.Persistence.EFCore.MetadataBuilder.<>c__DisplayClass3_0.<CreateMetaType>b__0(IProperty p)
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Breeze.Persistence.EFCore.MetadataBuilder.CreateMetaType(IEntityType et, Dictionary`2 dbSetMap)
at Breeze.Persistence.EFCore.MetadataBuilder.<>c__DisplayClass1_0.<GetMetadataFromContext>b__1(IEntityType et)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Breeze.Persistence.EFCore.MetadataBuilder.GetMetadataFromContext(DbContext dbContext)
at Breeze.Persistence.EFCore.MetadataBuilder.BuildFrom(DbContext dbContext)
at Breeze.Persistence.EFCore.EFPersistenceManager`1.BuildJsonMetadata()
at Breeze.Persistence.PersistenceManager.Metadata()
at JobtrackerBOBreezeController.metaData() in /Users/roydecaestecker/Documents/angular-cli-apps/sulo-solution/Sulo.Jobtracker.BO.Api/Controllers/JobtrackerBOBreezeController.cs:line 21
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Модель Klant
[Table("klant", Schema="Sulo")]
public class Klant
{
public Klant(){}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string naam { get; set; }
}
DBContext
using Microsoft.EntityFrameworkCore;
namespace Sulo.Jobtracker.Model
{
public class SuloJobtrackerContext : DbContext
{
public SuloJobtrackerContext(DbContextOptions options) : base(options) { }
public DbSet<Klant> klanten { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Klant>();
}
}
}
Файл проекта
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UserSecretsId>...</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Sulo.Jobtracker.Model\Sulo.Jobtracker.Model.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Breeze.AspNetCore.NetCore" Version="1.0.3.3" />
<PackageReference Include="Breeze.Persistence.EFCore" Version="1.0.3.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
</ItemGroup>
</Project>
Контроллер Breeze
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Linq;
using Breeze.Persistence;
using Breeze.AspNetCore;
using Microsoft.AspNetCore.Authorization;
[Breeze.AspNetCore.BreezeQueryFilter]
[Route("api/v1/[controller]/[action]")]
public class JobtrackerBOBreezeController {
private SuloJobtrackerPersistenceManager persistenceManager;
public JobtrackerBOBreezeController(SuloJobtrackerContext dbcontext){
persistenceManager = new SuloJobtrackerPersistenceManager(dbcontext);
}
[HttpGet, HttpOptions]
public string metaData() {
return persistenceManager.Metadata();
}
[HttpGet, HttpOptions]
[Authorize]
public IQueryable<Klant> klanten() {
return persistenceManager.Context.klanten;
}
}
вызов метода klanten () работает просто отлично