locked
Need sample for Projections concept which includes Complex Types RRS feed

  • Question

  • Hello Everyone,

     

    I am looking for a Sample which will explore about Projection Concept and Complex Type.

     

    please send me Link where i can get it.

     

    Thanks,

    Trinath Chakravarthi.

    Friday, May 28, 2010 9:52 AM

Answers

  • OK - you lost me...

    You said you want to create the view on the client side, so there's no need for any new type on the server. (At least that's my understanding).

    How/Where/Why would you use the complex type on the server?

    Thanks,


    Vitek Karas [MSFT]
    Monday, May 31, 2010 11:58 AM
    Moderator

All replies

  • Hi,

    Could you please be a little bit more specific as to what you're looking for?

    Is this on the server or on the client? Do you mean projection of complex property or property inside the complex type?

    Thanks,


    Vitek Karas [MSFT]
    Friday, May 28, 2010 2:21 PM
    Moderator
  • Hello Vitek Sir,

    i am looking for Projection sample on the client side.

    here i have created Complex Type in .edmx file as follows,

    name CustomData

    properties Name - String

    Count -Int64

    Address - String

    no complex property here.

    and i want to use this on Client Side.

    for kind, i need a sample.

     

    Thanks,

    Trinath Chakravarthi.

     

     

    Saturday, May 29, 2010 5:21 AM
  • Hi,

    If you use Visual Studio to "Add Service Reference" to your service the VS should automatically generate a class for your complex type and you can use it just like that. Note that the complex type will behave as a "black box" meaning WCF Data Services will manipulate with the entire complex type always (you can't ask for just part of it, update just part of it and so on). Other than that everything should just work.

    If you could provide more detailed scenario description of what you want to achieve, please let us know.

    Thanks,


    Vitek Karas [MSFT]
    Monday, May 31, 2010 10:38 AM
    Moderator
  • Hi Sir,

    Thanks for Your reply,

    My intension is, if we have 6 tables 

    i need to get columns from different table like VIEWS, 2 columns from one table 3 columns from another table like that

    for this i thought that Create a Complex Type then we can use it on Client Side in this case we wont use VIEWS.

    thats my Scenario.

    Any Sample for this Sir.

     

    Thanks. 

     

     

    Monday, May 31, 2010 11:23 AM
  • Hi,

    So you want to create a client side views, do I get it right?

    Assuming you have two tables (to simplify):

    Customers - ID, Name, Description

    Orders - ID, Quantity, Total, Customer

    Now I want something on the client which will have an instance for each order and it will have the Orders.Quantity and Customers.Name. To do this I could write something like:

    var results = ctx.Orders.Select(o =>
      new Order {
        Quantity = o.Quantity,
        Customer = new Customer {
          Name = o.Customer.Name
        }
      })
      .AsEnumerable()
      .Select(p =>
      new {
        Quantity = p.Quantity,
        CustomerName = p.Customer.Name
      });

    Note that the part of the query before the AsEnumerable will be executed on the server (will turn into a URL with $expand and $select). The part after the AsEnumerable will be executed on the client and it simply changes the shape of the results (from two entities per result, it creates a single object for each result).

    Now obviously you can replace anonymous type with precreated classes, so the result can be of your complex type for example.

    Thanks,


    Vitek Karas [MSFT]
    Monday, May 31, 2010 11:36 AM
    Moderator
  • Hello Sir,

    Yes Your Right but one problem is if i use Complex Type in Server Side,

    how i will access it in Client Side ?

    And can i have Sample for this , If possible??

    Thanks.

    Monday, May 31, 2010 11:50 AM
  • OK - you lost me...

    You said you want to create the view on the client side, so there's no need for any new type on the server. (At least that's my understanding).

    How/Where/Why would you use the complex type on the server?

    Thanks,


    Vitek Karas [MSFT]
    Monday, May 31, 2010 11:58 AM
    Moderator