Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using Entity Framework for my database in asp.net but when my database is on localhost it automatically add the tables and relationships but after I uploaded my database to host and I tried to use it in model.edmx it add tables without relationships.

I tried to add relationships with the object is in model.edmx but it automatically deleted my model.cs code and then I tried to make their relationships with coding but still not working

This is my code for tables in model.cs
C#
public partial class Cart
{
    public int id { get; set; }
    public string clientId { get; set; }
    public int productId { get; set; }
    public int amount { get; set; }
    public Nullable<System.DateTime> datePurchased { get; set; }
    public bool isInCart { get; set; }

    [InverseProperty("Cart")]
    public virtual Product Product { get; set; }
}

and this one
C#
public partial class Product
{
    public Product()
    {
        this.Carts = new HashSet<Cart>();
    }

    public int id { get; set; }
    public int typeId { get; set; }
    public string name { get; set; }
    public Nullable<double> price { get; set; }
    public string description { get; set; }
    public string image { get; set; }

    [ForeignKey("productId")]
    [InverseProperty("Product")]
    public virtual ICollection<Cart> Carts { get; set; }
}

i want to make a relationships between "id" in table product and "productId" in table cart
how can i do it?
With Respect
Posted
Updated 23-Aug-15 5:19am
v2
Comments
Wendelius 23-Aug-15 11:00am    
Is the relationship really so that one product has multiple carts? Should it be vice-versa?
Avenger1 23-Aug-15 11:04am    
yes, one product can be has multiple carts and "id" in Product table is primary key and i want to add "one to many" relationships
Abhipal Singh 23-Aug-15 14:30pm    
Check the links below to add relationships in edmx
https://msdn.microsoft.com/en-us/data/jj713299.aspx
https://msdn.microsoft.com/en-us/data/jj713564.aspx

Where exactly are you stuck?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900