0

If I have a POCO-Object (nothing to do with EF or any other Framework), and it looks like the following (from NoDb-Example):

public class TodoItem {
  public int TodoItemId { get; set; }
  public string Title { get; set; }
  public bool IsDone { get; set; }
}

How does Breeze know, or how do I tell Breeze, that TodoItemId is the EntityKey? Do I have to mess with the "MetaData"-By-Hand (http://www.breezejs.com/documentation/metadata-hand-depth)? I currently don't really understand, how the EntityKey-Concept can be configured/influenced.

Is there some kind of .NET-Attribute I can use? I use .NET-Framework 4.5 and Web API for the server-side.

NoRyb
  • 1,472
  • 1
  • 14
  • 35
  • What does your metadata look like? You either have to pass it down from the server or create it on the client, so somewhere you have to define a key. – PW Kad Jan 27 '14 at 14:41
  • I don't have anything yet. I'm still evaluating if I use Breeze and how I would do it. This is a question that popped up and I tried to find an answer in the docs. – NoRyb Jan 27 '14 at 14:47
  • Well it seems like a trivial question - somehow either in your database, your data layer ORM, or your client-side ORM (Breeze.js) you have to establish a key. If you want a non-relational data structure, you can do that as well, just define all of your entities as complex types. – PW Kad Jan 27 '14 at 14:55
  • But if I established a key (in my Database, be it in-memory) and say it is the "TodoItemId"-Property - how do I tell Breeze that this is the key to identify an object and not for example the Title-Property? – NoRyb Jan 27 '14 at 15:27
  • It depends, if you are using server side ORM (EF or w/e) you must establish it there and pass it down in the metadata. If you are going to write the metadata by hand in Breeze, you establish it there. – PW Kad Jan 27 '14 at 15:37
  • okay. So my question is: if I do it server side (in my case not EF, in my example it's just a c#-Class, nothing special) - where do it establish it and pass it down? Is it some kind of .NET-Attribute? I didn't find any examples - only on how to do it client side in JavaScript. – NoRyb Jan 27 '14 at 15:45
  • 1
    Yeah, so if you are not using EF and you are just using POCOs then you won't be creating metadata on the server, because you don't have any ORM to do so. – PW Kad Jan 27 '14 at 16:51
  • oh ok. So I take from your comment, that you need an ORM so you can create metadata on the server. Thank you for the answer - I didn't find this information in the breeze docs. – NoRyb Jan 28 '14 at 09:07

1 Answers1

0

I see you're referring to the Breeze NoDb example. That sample is all about not using Entity Framework on the server, which matches your scenario (just plain POCOs exposed via Web API).

In this style of server, no model metadata is exposed by the server so Breeze can't automatically know what entities are in your model and how they are related. Instead, you need to build this information on the client as you have correctly guessed.

To get an idea of what's involved when constructing client-side metadata, check out the Scripts\app\todo.model.js file in the Breeze NoDb example. In there you'll see how the metadata is built up and how the "isPartOfKey" attribute is used when describing the model to tell Breeze which property is the primary key.

On a side note, if you don't want to use Entity Framework for persistence but you'd like to generate the metadata automatically on the server from your POCOs you should have a read of Entity Framework as a metadata design tool in the Breeze documentation.

spoida
  • 2,655
  • 1
  • 23
  • 14
  • I was hoping that Breeze could read the MetaModel "directly" over Reflection somehow - instead this means, I would have to take a trip through the EF. But still that's better than nothing. Thank you for clarifying. – NoRyb Jan 29 '14 at 10:59