Ich möchte Datensätze mit Fremdschlüsseln hinzufügen, um nicht die Nummer ID zu schreiben.Datensatz hinzufügen in Methode Seed mit Fremdschlüssel Entity Framework
protected override void Seed(ClockShopEntities context)
{ ... } // Seed
private void AddType(ClockShopEntities context)
{
context.Typs.Add(new Typ { typName = "name1" });
context.Typs.Add(new Typ { typName = "name2" });
} // AddType
private void AddCountry(ClockShopEntities context)
{
context.Countries.Add(new Country { countryName = "country1" });
context.Countries.Add(new Country { countryName = "country2" });
context.Countries.Add(new Country { countryName = "country3" });
context.Countries.Add(new Country { countryName = "country4" });
} // AddCountry
Wie kann ich einen Wert hinzufügen, indem Sie einen Namen angeben?
// !!!!! with write id
private void AddFabricator(ClockShopEntities context)
{
context.Fabricators.Add(new Fabricator { fName = "", idCountry = 1 });
} // AddFabricator
// How can I write without Id
private void AddFabricator(ClockShopEntities context)
{
context.Fabricators.Add(
new Fabricator { fName = "", idCountry = ?? where Country = "country1" });
} // AddFabricator
ich Hilfe hoffen, Emma
Der Typ 'string' kann nicht implizit in 'bool' konvertiert werden. Der Lambda-Ausdruck kann nicht in den Delegattyp konvertiert werden, da einige der Rückgabetypen im Block nicht implizit in den Rückgabetyp des Delegierten konvertierbar sind. –
überprüfen Sie den aktualisierten Code, ich hatte ein Gleichheitszeichen in der Bedingung verpasst. – sachin
ja! Danke vielmals –