我想将产品添加到我的数据库,我需要从另一个表中获取类别ID,但是我不确定我该如何做到这一点?从另一个表中获取ID
基本上,我有一个表中包含我所有不同的类别,并且我需要从我的外部Web服务传递文本,然后打开数据库并获取它的意图所在的猫的ID。
下面是我的代码有:
using (aboDataDataContext dc = new aboDataDataContext())
{
var match = (from t in dc.tweProducts
where t.sku == productSku
select t).FirstOrDefault();
if (match == null)
{
tweProduct tprod = new tweProduct()
{
sku = p.productcode,
categoryId = Convert.ToInt32(catid),
title = p.name,
brand = p.manufacturer,
description = p.description,
twePrice = p.price,
weight = decimal.TryParse(p.size, out weight) == true ? (int?)weight : null,
size = decimal.TryParse(p.size, out weight) == true ? (int?)weight : null,
contry = p.country,
region = p.region,
vintage = int.TryParse(p.vintage, out vintage) == true ? (int?)vintage : null,
strength = p.strength,
bottler = p.bottler,
age = int.TryParse(p.age, out age) == true ? (int?)age : null,
caskType = p.casktype,
series = p.series,
flavour = p.flavour,
stock = p.freestock,
tweUpdated = false,
stockUpdated = false,
priceUpdated = false,
dataUpdated = false,
imgPublished = false,
lastUpdated = DateTime.Now,
};
}
}
所以基本上从Web服务的类别传递Category_1(例如),我需要这个传递给我的数据库,以获取Category_1的ID (说它的1),然后将其插入我的表。
是否的LINQ to SQL或实体框架此LINQ到实体?你有导航属性映射? – abatishchev