Answer the question
In order to leave comments, you need to log in
How to add data to table which is navigation property?
public class Product
{
public int Id { get; set; }
public string ProductName { get; set; }
public int? CountryId {get; set; }
public virtual Country Country { get; set; }
}
public class Country
{
public int Id { get; set; }
public string CountryName { get; set; } // command name
public virtual ICollection Products { get; set; }
public Country()
{
Products = new List();
}
public override string ToString()
{
return CountryName;
}
On the form I throw datagrid. I set the Product table as the data source
The question is this. When I add data to the "Name" column, everything is perfectly saved in the database. If I add data to the "Country" column, I get an error about not converting Syste.String to "DatabaseName.Country"
How to deal with this?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question