สรุป
ฉันได้แก้ไขโซลูชัน nopCommerce เพื่อรวมเอนทิตีใหม่ด้วยแนวทาง CodeFirst ซึ่งได้อัปเดตฐานข้อมูลได้สำเร็จดังที่แสดงในภาพด้านล่าง
รูปภาพที่ฐานข้อมูลมีการอัปเดตตาราง
เมื่อฉันพยายามเข้าถึงตารางพื้นที่เก็บข้อมูลซึ่งถูกแทรกผ่าน AutoFrac ฉันจะได้รับแถวที่ส่งคืนโดยพื้นที่เก็บข้อมูล แต่คอลัมน์ทั้งหมดแสดงค่าว่าง โปรดทราบว่าจำนวนแถวในตารางจะเหมือนกับจำนวนที่เห็นในตารางฐานข้อมูล ดังนั้นจึงดูเหมือนว่าจะเชื่อมต่อกันแต่ไม่แสดงค่า
{
public partial class NutrientService : INutrientService
{
#region fields
protected readonly IRepository<ProductNutrient> _productNutrientRepository;
#endregion fields
#region Ctor
public NutrientService(IRepository<ProductNutrient> productNutrientRepository)
{
_productNutrientRepository = productNutrientRepository;
}
#endregion Ctor
public IList<ProductNutrient> GetNutrients()
{
var query = from p in _productNutrientRepository.Table
select p as ProductNutrient;
var list = query.ToList();
return list;
}
public IList<ProductNutrient> GetNutrientsByProductID()
{
var query = from p in _productNutrientRepository.Table
select p as ProductNutrient;
var list = query.ToList();
return list;
}
}
}
การดีบักแสดงค่า Null ที่ส่งคืนจากพื้นที่เก็บข้อมูล
คำจำกัดความของตารางใน SQL Management Studio
public class ProductNutrient : BaseEntity
{
public int NutrientID;
public int ProductID;
public string Nutrient;
public bool ShowLessThan;
public decimal Value;
public string Unit;
}
}
พื้นที่เก็บข้อมูลใช้งานได้กับตารางอื่น แต่นี่คือรหัสของพื้นที่เก็บข้อมูลอยู่ดี
/// </summary>
public virtual IQueryable<TEntity> Table => Entities;
/// <summary>
/// Gets an entity set
/// </summary>
protected virtual ITable<TEntity> Entities => _entities ?? (_entities = _dataProvider.GetTable<TEntity>());
#endregion
}
select p as ProductNutrient;
อาจจะไม่ทำตามที่คุณคิดp
เป็นอย่างอื่น ทำไมคุณถึงโยนมันต่อไป? แต่เราไม่สามารถมองเห็นพื้นที่เก็บข้อมูลได้ (โดยเฉพาะสิ่งที่อยู่เบื้องหลัง_productNutrientRepository.Table
) และถึงกระนั้น ก็สามารถถามคำถามได้โดยไม่ต้องใช้รูปภาพทั้งหมด - person Gert Arnold   schedule 07.01.2021