views:

66

answers:

1

I have a Product table with fields like:

public class Product {
    public int ID {get;set;}
    ...
}

and a table that joins Products to other "cross sell" products (like items):

public class CrossSell {
    public int ProductID {get;set;}
    public int CrossSellID {get;set;}
}

My intent is, given any product, get a list of cross sell products.

Entity Framework 4 (EF second edition) takes these tables and creates a Product and Product1 relation, where the line that joins the table is called a CrossSell.

What I want to have is:

public class Product {
    public int ID {get;set;}
    ...
    public IList<Product> CrossSells {get;set;}
}

EF created this:

public class Product {
    public int ID {get;set;}
    ...
    public IList<Product> Products {get;set;}
    public IList<Product> Products1 {get;set;}
}

Could I simply delete the the second List called Products1, rename the first to "CrossSells" and have all this just magically work? Should I remake the SQL tables differently so EF better understands my intent? What would these SQL tables look like if a single product can have multiple cross sell items?

EDIT:

What I am really looking for is a way to represent CrossSell items in EF without a circular reference. Right now, Product refers to other products which in turn refer to other products which in turn ...

+2  A: 

Find the entity in Model Browser. Find the Products1 property. Click it. Rename it in the property editor.

Craig Stuntz
Could I ignore (or delete) the other relation? Doesn't all the EF properties need to be present in the POCO? The effect is creating this circular reference, where I only need one product related to one or more other products. I guess I could have a "Group Number" as a single field in the Product table and select all products having the same number. Just have to figure out how to get that in an "IList<Product> Products" property using EF.
Dr. Zim
Yes, you can delete the other relationship. The EF 1 designer didn't like this, but in EF 4 it's OK.
Craig Stuntz