locked
EF, Web API No Keys RRS feed

  • Question

  • Hello,

    I am really new to EF and web api.  

    We are trying to expose some odata services via web api and EF to our oracle dbase.  

    We don't have keys specified in numerous of the oracle tables we need to hit.  I know bad design but it is what is.  I cannot change the table structure currently.

    I am building out my Models via the EF design from tables option.  

    My questions are.  

    1. when I go in to my edmx and try and build out some of the relationships i cannot get it to work. i can create the keys here but when i do the association option and try and set the relationship i get all sorts of errors.  

    2. instead of doing the above, can i some how do this via code.  So for example.  I am looking at an order and i am being routed to the lines of the order, can i get the lines for that order and send them to the user?  

    3. I am trying to use attribute based routing. Remember, no keys so none of my models are related.  if i can do #2, can i setup a route to look then something like this /Orders(123)/Lines to get all lines for an order?  I have tried this but get this error:

    Additional information: The path template 'Orders({key})/Lines' on the action 'SingleOrdersNumber' in controller 'Orders' is not a valid OData path template.

    Any help would be great here. 

    Friday, August 12, 2016 7:52 PM

Answers

  • Hi olson2334,

    >>1. when I go in to my edmx and try and build out some of the relationships i cannot get it to work. i can create the keys here but when i do the association option and try and set the relationship i get all sorts of errors.  

    As DA924x said, we could not use entity framework without primary key. Because Entity Framework relies on every entity having a key value that it uses for tracking entities.

    >>2. instead of doing the above, can i some how do this via code.  So for example.  I am looking at an order and i am being routed to the lines of the order, can i get the lines for that order and send them to the user?  

    It seems that you we could retrieve related records by using raw SQL. like this:

    using (var context = new BloggingContext()) 
    { 
        var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList(); 
    }

    For more information, please refer to:

    https://msdn.microsoft.com/en-us/data/jj592907.aspx

    http://www.mikesdotnetting.com/article/252/mvc-5-with-ef-6-in-visual-basic-advanced-entity-framework-scenarios#rawsql

    >>3. I am trying to use attribute based routing. Remember, no keys so none of my models are related.  if i can do #2, can i setup a route to look then something like this /Orders(123)/Lines to get all lines for an order?  I have tried this but get this error:

    It seems that it 's web api issue, I would suggest post your issue on web api forum for help.

    https://forums.asp.net/1246.aspx/1?Web+API

    Best regards,

    Cole Wu


    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.

    Monday, August 15, 2016 4:57 AM

All replies

  • You don't have any primary-keys I don't think EF is going to work for you. Maybe you need to develop an object code generator.

    Sunday, August 14, 2016 3:25 PM
  • Hi olson2334,

    >>1. when I go in to my edmx and try and build out some of the relationships i cannot get it to work. i can create the keys here but when i do the association option and try and set the relationship i get all sorts of errors.  

    As DA924x said, we could not use entity framework without primary key. Because Entity Framework relies on every entity having a key value that it uses for tracking entities.

    >>2. instead of doing the above, can i some how do this via code.  So for example.  I am looking at an order and i am being routed to the lines of the order, can i get the lines for that order and send them to the user?  

    It seems that you we could retrieve related records by using raw SQL. like this:

    using (var context = new BloggingContext()) 
    { 
        var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList(); 
    }

    For more information, please refer to:

    https://msdn.microsoft.com/en-us/data/jj592907.aspx

    http://www.mikesdotnetting.com/article/252/mvc-5-with-ef-6-in-visual-basic-advanced-entity-framework-scenarios#rawsql

    >>3. I am trying to use attribute based routing. Remember, no keys so none of my models are related.  if i can do #2, can i setup a route to look then something like this /Orders(123)/Lines to get all lines for an order?  I have tried this but get this error:

    It seems that it 's web api issue, I would suggest post your issue on web api forum for help.

    https://forums.asp.net/1246.aspx/1?Web+API

    Best regards,

    Cole Wu


    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.

    Monday, August 15, 2016 4:57 AM