I have 2 tables in my SQL Server. They have a foreign key relationship. I now want to add a new record to the table with the index. For this I want to use the ID of the primary key. I don't know how to write the statement in my C# to add this ID to the record.
I already tried some stuff, but because I'm new to this topic I don't how much sense it makes ^^
e.g.
ArticleId = db.TestArtikel.Where(x => x.Name == "test1")
public static void AnotherFunction()
{
using (DbEntities db = new DbEntities())
{
db.TestProduct.Add(new TestProduct()
{
ProductId = Guid.NewGuid(),
Price = 10,
DeliveryDate = DateTime.Now,
ArticleId =
});
db.SaveChanges();
}
}
When I use the the line above the code for the ArticleId, it throws the error:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Guid'
SingleOrDefault().