none
Linq 2 sql join creating strong type

    Question

  • Hi ...

    Is it possible to do a linq2sql join (only one trip to the database), and immediately create a strongly typed object (ie not anonymous ??)

    Something like:

    var xxx = (from i in images

    join a in actuals on a.key equals i.key

    select new Type { ... = ...., .... = ..... }

    I tried it but it gives me an error saying you cannot do this with linq to sql (only create anonymous types )

    Wednesday, May 07, 2014 6:15 PM

Answers

  • Hello,

    >>Is it possible to do a linq2sql join (only one trip to the database), and immediately create a strongly typed object (ie not anonymous ??)

    No, we need to firstly define the DTO class as below:

    class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                DFDBEntities db = new DFDBEntities();
    
                var resutl = from order in db.Orders
    
                             select new OrderDTO { ID = order.OrderID };
    
            }
    
        }
    
        class OrderDTO
    
        {
    
            public int ID { get; set; }
    
    }
    

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 08, 2014 6:29 AM