locked
Custom class/type POCO in EF 4.0 RRS feed

  • Question

  • I am using a .net Entityframework model and expose it to the client via WCF Data Services. So far so good. Now, I need to declare an in-memory custom class. WHere and how do I do that? In native WCF it is very easy. Here is a code snippet...

     var query = from c in context.Corridors
                            join s in context.Schedules on c.CorridorID equals s.CorridorID
                            join t in context.Trains on s.ScheduleID equals t.ScheduleID
                            select new UITrain
                            {
                                CorridorID = c.CorridorID,
                                TrainID = t.TrainID,
                                TrainNumber = t.TrainNumber,
                                IsSelected = false
                            };

    So, where and how do I declare UITrain. It is custom type/class and does not need to be associated with the database. 
    It is just for in-memory stuff.

    Thanks

    --tolga

    Kemal Tolga Koseoglu Application Developer WATG
    Monday, December 13, 2010 6:00 PM

Answers

  • Kemal

    Not clear on what you are trying to achieve. Will you be returning this custom class back to the client ?

    You can always create POCO i.e. plain old clr classes anywehere in your namespace. but will it be visible through WCF data Service - well - that depends on couple of things. In the WCF data service class file you can always write your custom operation like GetUITrain. But its return type has to be IQueryable<T>. where T can be your custom class. Make sure that your custom class defines a dataservicekey coz it acts like a primary key on your class.

    Then within the GetUITrain function you can write the query you have written in the post. You would have to specifiy operationacessrule for the clients to acess this custom method. this method is queryable from the URI itself for e.g. http://<yourserver>:<port>/<yourapp>/<odataservice>/GetUITrain

    Hope this helps.

    PS : mark this as an answer if this is what you were searching for


    kashyapa
    Tuesday, December 14, 2010 6:47 PM

All replies

  • Kemal

    Not clear on what you are trying to achieve. Will you be returning this custom class back to the client ?

    You can always create POCO i.e. plain old clr classes anywehere in your namespace. but will it be visible through WCF data Service - well - that depends on couple of things. In the WCF data service class file you can always write your custom operation like GetUITrain. But its return type has to be IQueryable<T>. where T can be your custom class. Make sure that your custom class defines a dataservicekey coz it acts like a primary key on your class.

    Then within the GetUITrain function you can write the query you have written in the post. You would have to specifiy operationacessrule for the clients to acess this custom method. this method is queryable from the URI itself for e.g. http://<yourserver>:<port>/<yourapp>/<odataservice>/GetUITrain

    Hope this helps.

    PS : mark this as an answer if this is what you were searching for


    kashyapa
    Tuesday, December 14, 2010 6:47 PM
  • Hi,

    Could you please tell us how is the problem now?  

    If you need any help, please feel free to let me know.

    Have a nice weekend!


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 17, 2010 1:29 AM
    Moderator