Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> LLBLGen and Json
 

Pages: 1
Architecture
LLBLGen and Json
Page:1/1 

  Print all messages in this thread  
Poster Message
mdissel
User



Location:

Joined on:
16-Sep-2003 10:10:25
Posted:
92 posts
# Posted on: 31-Jan-2008 22:56:28.  
Hello

I searched in this forum for json, but no results. Nobody used llblgen with some Ajax based website that uses json to load data from the server? If you convert the current IEntity objects to json you get a lot of overhead. I'm only interested in the database / custom fields from the IEntity. I could create a template that creates the minimal classes, but i wonder if anyone else has done this already.

Thanks

Marco
  Top
jmeckley
User



Location:
Harrisburg, PA, USA
Joined on:
05-Jul-2006 16:03:19
Posted:
403 posts
# Posted on: 01-Feb-2008 14:34:12.  
since your only interested in specific properties, I would map the entity to a dto and json/serialize the dto.

Jason Meckley
Programmer
 
Top
mattsmith321
User



Location:
Austin, TX
Joined on:
04-Oct-2004 21:45:32
Posted:
146 posts
# Posted on: 01-Feb-2008 15:39:20.  
jmeckley wrote:
since your only interested in specific properties, I would map the entity to a dto and json/serialize the dto.

I agree. And use the latest AjaxPro assembly to get compliant JSON.
Matt Smith
http://myhomepoint.com - Powering the Modern Family
http://swoofware.com - It’s only work if somebody makes you do it
 
Top
mdissel
User



Location:

Joined on:
16-Sep-2003 10:10:25
Posted:
92 posts
# Posted on: 01-Feb-2008 16:01:18.  
jmeckley wrote:
since your only interested in specific properties, I would map the entity to a dto and json/serialize the dto.


Anyone already made a simple DTO template?


  Top
jmeckley
User



Location:
Harrisburg, PA, USA
Joined on:
05-Jul-2006 16:03:19
Posted:
403 posts
# Posted on: 01-Feb-2008 16:05:01.  
my projects are smaller in size and dto are specific to the gui, so I code dtos manually.
search the template studio forum. there are templates for 2.0. if your using 2.5 they need to be tweaked slightly. not sure how, as I'm using 2.0.
Jason Meckley
Programmer
 
Top
JoshWright
User



Location:
Norman, Oklahoma
Joined on:
05-Sep-2008 02:17:54
Posted:
12 posts
# Posted on: 05-Sep-2008 02:36:03.  
I don't know if you're still looking to serialize LLBLGen entities to json, but I've got a solution that may work for you. It's built for the Self Servicing pattern (version 2.6), but it probably wouldn't be too hard to make it work with Adapter.

Basically there's a couple of extension methods that let you list fields or related entities (with their fields) and it will serialize everything with minimal code.

Here's an example that would serialize the BuyerName and Price for an Order Entity:

Code:

//Result:
//{"BuyerName":"Ben Franklin","Price":49.95}

order.ToJSon(
OrderFields.BuyerName,
OrderFields.Price
);


Here's a larger example that serializes some fields on Order, then some other fields on the related entities Product, Address, and State:

Code:

//Result:
//{"BuyerName":"Ben Franklin","Price":49.95,"Product":{"Name":"Headphones"},"Address":{"City":"Oklahoma City","State":{"Name":"Oklahoma"}}}

order.ToJSon(
    OrderFields.BuyerName,
    OrderFields.Price,
    OrderEntity.Relations.ProductEntityUsingProductId.With(
        ProductFields.Name
    ),
    OrderEntity.Relations.AddressEntityUsingShippingAddressId.With(
        AddressFields.City,
        AddressEntity.Relations.StateEntityUsingStateId.With(
            StateFields.Name
        )
    )
);


No promises about the quality, but it has unit tests and it's worked for me so far. Note that you do have to prefetch whatever you want to serialize (it won't do lazy loading).


  Top
swallace
User



Location:
Oklahoma City, Oklahoma, USA
Joined on:
18-Aug-2003 15:34:29
Posted:
648 posts
# Posted on: 11-Sep-2008 19:04:31.  
Josh, that's great code. Thanks for sharing. I hope Otis will make it an inclusion in the user code area.

For others, be sure to seek out Josh's blog for specific implementation details:

http://www.readingwright.com/Post/Show/LLBLGen-to-JSon



  Top
tprohas
User



Location:
Tucson, AZ
Joined on:
23-Mar-2004 00:00:43
Posted:
257 posts
# Posted on: 04-Jun-2009 20:09:48.  
Hello all,

I've been using LLBLGen Pro for a while now but don't know how to add an extension to it. Can someone please explain how I go about using this serializer?

BTW, Thank you very much for this code. This is exactly what I've been trying to figure out how to do. Regular Smiley


Aaron Prohaska
http://www.verdesoft.com/
 
Top
trevorg
User



Location:
Canada
Joined on:
15-Nov-2007 19:13:40
Posted:
104 posts
# Posted on: 18-Feb-2010 18:46:41.  
Just a heads up on Josh's example....to see the extension method, you must include:

using LLBLGenExtensions.EntityExtensions.JSon;
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.