locked
Entity Framework View For Multiple Database Invalid Column Name RRS feed

  • Question

  • Dear All

    Thanks in advance.

    I would like to access a view through EF4 which join table in another database in same server

    View 'OrderShipping'

    SELECT oo.Id, oo.OrderNumber, ss.ShippingNumber FROM Orders AS oo
    
    LEFT JOIN [AnotherDatabase].dbo.Shipping AS ss
    
    ON oo.Id = ss.OrderId

    I add the view in my entity framework.

    It compiles correctly.

    However, when run the code to access the view 'OrderShipping'

    using (OrderManagementEntities context = new OrderManagementEntities ())
    {
    
      IQueryable<OrderShipping> orderShippings = context.OrderShippings.Where(o=>o.Id == Id);
    
    ...
    
    }

    It raise an error 'Invalid column name 'XXX'.'

    Is it possible to access a view which data across two databases?

    How I could achieve the same result if it is not supported?

    Thanks.

    Best Regards

    mintssoul


    Best Regards
    mintssoul


    • Edited by mintssoul Tuesday, September 1, 2015 1:59 AM
    Tuesday, September 1, 2015 1:47 AM

Answers

  • Thanks

    Finally the problem gone,  it was some problem about the view query.


    Best Regards
    mintssoul

    • Marked as answer by Fred Bao Tuesday, September 8, 2015 1:16 AM
    Friday, September 4, 2015 7:00 AM

All replies

  • I know that you would need two database contexts a context for each database. I don't think you can do a Join on two tables across two database contexts. I have never seen it done, and I could be wrong.
    Tuesday, September 1, 2015 3:58 AM
  • Thanks

    Finally the problem gone,  it was some problem about the view query.


    Best Regards
    mintssoul

    • Marked as answer by Fred Bao Tuesday, September 8, 2015 1:16 AM
    Friday, September 4, 2015 7:00 AM