A
A
AndNovak2016-08-04 21:52:25
C++ / C#
AndNovak, 2016-08-04 21:52:25

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
29e5edac0ae54f9f8d281d850e40c88d.png
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

1 answer(s)
A
AndNovak, 2016-08-05
@AndNovak

Yes, just the name of the country. I understand why this is happening, but there is no way to fix it. Not enough experience yet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question