0
votes

I have Breeze.Sharp application which communicates with legacy WebAPI which doesn't provide metadata.

Query seems to be executed properly - expected number of objects is returned but all of them are empty. Modifying query parameters also works - number of returned objects changes as expected. I was playing around with EntityManager.MetadataStore but nothing helped.

Here is the final code I'm currently using to communicate with WebAPI.

public class DokumentModelBreeze: BaseEntity
{
    public string id { get; set; }
    public string numer { get; set; }
    public decimal suma { get; set; }
}    

...

Configuration.Instance.ProbeAssemblies(typeof(DokumentModelBreeze).Assembly);

var manager = new EntityManager("http://localhost:52357/api/");
manager.DataService.HasServerMetadata = false;

var store = manager.MetadataStore;
store.SetResourceName("dokumenty", typeof(DokumentModelBreeze), true);
store.NamingConvention = new CamelCasePropertiesNamingConvention();

var builder = new EntityTypeBuilder<DokumentModelBreeze>(store);
builder.DataProperty(d => d.id).IsPartOfKey();
using(TextWriter writer = File.CreateText("C:/metadata.txt")) {
    store.ExportMetadata(writer);

var query = new EntityQuery<DokumentModelBreeze>("dokumenty");
query = query.WithParameter("nrFirmy", 1).Where(p => p.numer=="123");
var results = await manager.ExecuteQuery<DokumentModelBreeze>(query);
List<DokumentModelBreeze> Dokumenty = new List<DokumentModelBreeze>();
foreach(var item in results)
    Dokumenty.Add(item);

In the last foreach loop every item is of type DokumentModelBreeze but each member property equals to null or 0 respectively.

I have saved MetadataStore to file, it is included below:

{
  "metadataVersion": "1.0.3",
  "namingConvention": {
    "clientServerNamespaceMap": {},
    "name": "camelCaseProperties"
  },
  "structuralTypes": [
    {
      "shortName": "BaseEntity",
      "namespace": "Breeze.Sharp",
      "baseTypeName": "",
      "autoGeneratedKeyType": "None"
    },
    {
      "shortName": "DokumentModelBreeze",
      "namespace": "BRuNETWPF.ViewModels",
      "baseTypeName": "BaseEntity:#Breeze.Sharp",
      "autoGeneratedKeyType": "None",
      "defaultResourceName": "dokumenty",
      "dataProperties": [
        {
          "name": "id",
          "dataType": "String",
          "isNullable": false,
          "defaultValue": "",
          "isPartOfKey": true
        },
        {
          "name": "numer",
          "dataType": "String",
          "isNullable": false,
          "defaultValue": ""
        },
        {
          "name": "suma",
          "dataType": "Decimal",
          "isNullable": false,
          "defaultValue": 0.0
        }
      ]
    }
  ],
  "resourceEntityTypeMap": {
    "dokumenty": "DokumentModelBreeze:#BRuNETWPF.ViewModels"
  }
}

Am I missing something here or perhaps Breeze# doesn't allow to query WebAPI without metadata ? The same code executed against test WebAPI with exposed metadata works well.

1

1 Answers

1
votes

Your GetValue and SetValue properties must be defined like so:

    public string id
    {
        get { return GetValue<string>("id"); }
        set { SetValue(value); }
    }

It's a pain, I know, but this fixed it for me after one of our awesome tech leads pointed it out :)