質問

In the following example I got a warning that Item class was not found. The Batch class was fine even though it was located in the same namespace.

Did Batch work due to that it was attached in the code behind (QueueModel:Json)?

Is this by design or should it be more consistent?

{
   $:{DataType:"Batch"},
   BatchID:123456778,
   Name:"BatchName",
   Items: [
     {
       Message:"Hello my friend!"
     }
   ],
   $Items:{DataType:"MyCompany.Concepts.Item"}
} 
役に立ちましたか?

解決

If the database classes lives in the same namespace as your Json derived class, then you only need to specify the class name. If there is a code behind class (a partial class), then you do not need to specify the DataType property in the json-by-example file.

So it needs to be provided either in the .json file or in the (optional) code behind class.

person-viewmodel.json:

{
   "FirstName":"Albert",
   "LastName":"Einstein",
   "Phonenumbers": [
      {
         "Type":"mobile"
         "Number":"1234"
      }
   ],
   "$Phonenumbers":{"DataType":"MyDatabaseNamespace.Phonenumber"}
}

person-viewmodel.json.cs:

public class PersonViewModel : Json<Person> {
}

So if you only use the json-by-example file (no code behind), you will need to provide the bound database type:

person-message.json:

{
   "$":{"DataType":"MyDatabaseNamespace.Person"},
   "FirstName":"Albert",
   "LastName":"Einstein",
   "Phonenumbers": [
      {
         "Type":"mobile"
         "Number":"1234"
      }
   ],
   "$Phonenumbers":{"DataType":"MyDatabaseNamespace.Phonenumber"}
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top