我想將產品添加到我的數據庫,我需要從另一個表中獲取類別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