none
How to model these 2 entities with relationship? RRS feed

  • Question

  • Insurance
    {
      string Coverage
    }
    
    Lookup
    {
      string Group
      string Coverage
    }

    assuming the above as tables/entities.
    in sql:

    select * from Insurance AS Ins
    Left Join Lookup AS Lkp
    ON Ins.Coverage = Lkp.Coverage
    AND Lkp.Group = "CoverageType"
    ;

    there's no referential/relationship defined at db level.
    so when i gen the model, they both have no relationship.

    I intend to introduct Insurance.LookupCoverage prop
    how should I do it ?

    I tried create Association between them, but the result is using Lookup.Id = Insurance.*(whatever field), I can't change the Lookup field.

    Tuesday, March 20, 2012 10:37 AM

Answers

  • Hi Kelmen,

    The navigation is relied on foreign key. I think you use LINQ query to achieve the join T-SQL:

    var leftjoin= from i in Insurances join l in Lookups on new{i.Coverage,Group="CoverageType"} equals new{l.Coverage,l.Group} 
    into Joined
    from j in Joined.DefaultIfEmpty()
    select new
    {
    Converage= i.Coverage
    } 

    Have a nice day.

    Alan Chen[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.

    • Marked as answer by Kelmen Monday, March 26, 2012 7:36 AM
    Wednesday, March 21, 2012 7:24 AM
    Moderator

All replies

  • Hi Kelmen,

    The navigation is relied on foreign key. I think you use LINQ query to achieve the join T-SQL:

    var leftjoin= from i in Insurances join l in Lookups on new{i.Coverage,Group="CoverageType"} equals new{l.Coverage,l.Group} 
    into Joined
    from j in Joined.DefaultIfEmpty()
    select new
    {
    Converage= i.Coverage
    } 

    Have a nice day.

    Alan Chen[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.

    • Marked as answer by Kelmen Monday, March 26, 2012 7:36 AM
    Wednesday, March 21, 2012 7:24 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?
    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[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.

    Monday, March 26, 2012 1:49 AM
    Moderator