Author |
Share Topic Topic Search Topic Options
|
munissor
Newbie
Joined: 08-Nov-2012
Location: Ireland
Posts: 1
|
Post Options
Quote Reply
Topic: Breeze without EF Posted: 08-Nov-2012 at 4:41am |
I'm in the same situation, I'm trying to use breeze in a project where a DbContext is not there. The approach is was following was to try to create the metadata on the client side, attaching it to the metadataStore. However, after all the configuration the MetadataStore appears to be empty, and is still calling the Metadata endpoint. This is the code I used for configuring an entity type.
var breeze = root.breeze; var serviceName = 'http://.../api'; var metadataStore = new breeze.entityModel.MetadataStore();
// create a UserEntity var userEntityType = new breeze.entityModel.EntityType({ metadataStore: metadataStore, serviceName: serviceName, shortName: "User", }); userEntityType.addProperty(new breeze.entityModel.DataProperty({ name: "Id", isPartOfKey:true })); userEntityType.addProperty(new breeze.entityModel.DataProperty({ name: "Name" }));
breeze.core.config.setProperties({ trackingImplementation: breeze.entityModel.entityTracking_ko, remoteAccessImplementation: breeze.entityModel.remoteAccess_webApi });
// NOTE: at this point metadataStore.isEmpty() returns true // but metadataStore.getEntityTypes() return the configured entity
// make the breeze manager available to the page as a property of the root object root.ConfiguredEntityManager = new breeze.entityModel.EntityManager({ serviceName: serviceName, metadataStore: metadataStore, });
|
There is something that we are doing wrong?
|
|
pawel
Newbie
Joined: 21-Sep-2012
Posts: 12
|
Post Options
Quote Reply
Posted: 02-Nov-2012 at 12:49am |
Try to return the following string:
{"conceptualModels":{"schema":{"xmlns":"http://schemas.microsoft.com/ado/2009/11/edm","xmlns:cg":"http://schemas.microsoft.com/ado/2006/04/codegeneration","xmlns:store":"http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator","namespace":"THE_NAMESPACE_OF_THE_DTO_CLASSES_HERE","alias":"Self","xmlns:annotation":"http://schemas.microsoft.com/ado/2009/02/edm/annotation","annotation:UseStrongSpatialTypes":"false","entityContainer":{"name":"Model1Container","annotation:LazyLoadingEnabled":"true"}}}}
The same as a string const (should be a single line):
const string emptyMeta = @"{\""conceptualModels\"":{\""schema\"":{\""xmlns\"":\""http://schemas.microsoft.com/ado/2009/11/edm\"",\""xmlns:cg\"":\""http://schemas.microsoft.com/ado/2006/04/codegeneration\"",\""xmlns:store\"":\""http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator\"",\""namespace\"":\""THE_NAMESPACE_OF_THE_DTO_CLASSES_HERE\"",\""alias\"":\""Self\"",\""xmlns:annotation\"":\""http://schemas.microsoft.com/ado/2009/02/edm/annotation\"",\""annotation:UseStrongSpatialTypes\"":\""false\"",\""entityContainer\"":{\""name\"":\""Model1Container\"",\""annotation:LazyLoadingEnabled\"":\""true\""}}}}";
Edited by pawel - 02-Nov-2012 at 12:57am
|
|
kaanse
Newbie
Joined: 28-Oct-2012
Location: Turkey
Posts: 10
|
Post Options
Quote Reply
Posted: 31-Oct-2012 at 11:55am |
how can i return empty metadata when i tried to return null i am getting same error can you give a example about that
thanx for help
|
|
jtraband
IdeaBlade
Joined: 19-Sep-2012
Posts: 55
|
Post Options
Quote Reply
Posted: 31-Oct-2012 at 10:33am |
Currently, you have to return "some" metadata, but it can be empty. We will change this in a later release but for now, just expose an empty EF model.
|
|
kaanse
Newbie
Joined: 28-Oct-2012
Location: Turkey
Posts: 10
|
Post Options
Quote Reply
Posted: 31-Oct-2012 at 8:23am |
when i return i querable object its searching metedata fist how can i fix this i just want to take all data from method (getUnits)
----------- var serviceName = '/DocIndex'; var manager = new entityModel.EntityManager(serviceName); -----------
should i use something differnt instead of "DataProperty"
thanx for help
Edited by kaanse - 31-Oct-2012 at 8:31am
|
|
jtraband
IdeaBlade
Joined: 19-Sep-2012
Posts: 55
|
Post Options
Quote Reply
Posted: 15-Oct-2012 at 9:49am |
Actually, we do use most of what is in the EDMX conceptual model. But if you want to specify the metadata yourself, you can do something like this:
var fooEntityType = new breeze.entityModel.EntityType(myMetadataStore); var dp1 = new breeze.entityModel.DataProperty(...); // take a look at the api docs for DataProperty fooEntityType.appProperty(dp1); var dp2 = new breeze.entityModel.NavigationProperty(...); // take a look at the api docs for NavigationProperty
Most of the metadata that you will need to define is contained in the DataProperties and NavigationProperties that make up each EntityType.
|
|
pawel
Newbie
Joined: 21-Sep-2012
Posts: 12
|
Post Options
Quote Reply
Posted: 15-Oct-2012 at 2:48am |
I would like to provide Metadata()! Just post some specification of what breeze expects. Currently I extract "ConceptualModels" this from EDMX, but I would like to know what is used and what is ignored (the string is rather long).
|
|
jtraband
IdeaBlade
Joined: 19-Sep-2012
Posts: 55
|
Post Options
Quote Reply
Posted: 11-Oct-2012 at 11:17am |
Absolutely, this is supported. We simply haven't gotten around to documenting it or providing samples yet. There are also still some rough edges here but we should have some basic information on this topic out within the next few weeks.
For now, the simplest way to get started with this right now is to simply return an IQueryable<Object> from your ApiController
public class MyController : ApiController {
// We'll assume that you cannot provide this. // [AcceptVerbs("GET")] // public String Metadata() { // return ContextProvider.Metadata(); // }
[AcceptVerbs("GET")] public IQueryable<Object> MyObjects() { var stuff =this.GetMyObjects().AsQueryable(); return stuff; } }
Notice that there is no ContextProvider in this case. Querying for MyObject from the Breeze client then looks something like this:
var query = EntityQuery.from("MyObjects") .where("City", "startsWith", "San") .take(5) var myEntityManager.executeQuery(query).then(...)
This assumes that the type of the instances returned by MyObjects contains a property "City". The Breeze server side code will still translate your client side queries into valid linq queries against the IQueryable provided on the server.
This query will return "plain" json objects withing the breeze promise method or callback. If you want these objects to be converted to "first class" breeze entities during the query process, then you will need to provide metadata for each type returned. This metadata is normally returned from the server but it can also be provided client side via the use of the EntityType, DataProperty and Navigation property ctors. (see the apidocs for more detail on this).
Hope this helps,
|
|
pawel
Newbie
Joined: 21-Sep-2012
Posts: 12
|
Post Options
Quote Reply
Posted: 10-Oct-2012 at 12:56am |
Can Breeze be used with WebApi, but without Entity Framework? I have different ORM framework and would like to write custom DTO (POCO + DataAnnotations) for client/server communication. If this is already possible, please help me get started. If this is currently impossible, are there plans to allow such scenarios?
|
|