gpt4 book ai didi

c# - 正确使用表中列值中的列表?

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:23 24 4
gpt4 key购买 nike

这是我正在使用的 JSON 文件的结构。

{
"date": "2015-11-11",
"retailer_id": "CLD001",
"orders": [
{
"products": [
{
"product_id": "53743443003",
"quantity": 4,
"unit_price": 42.71
}
],
"value": 170.84,
"customer": {
"id": 58
}
}
]
}

为了处理这个 Json 文件,我创建了 3 个单独的类来包含 productsOrdered、OrderItems 和 RetailerOrders 的信息。是说sql无法将类型匹配到通用系统列表?

 [Table]
public class OrderItems : INotifyPropertyChanged, INotifyPropertyChanging
{
private List<ProductsOrdered> po = new List<ProductsOrdered>();
private double TotalPrice;
private int customer_id;

///this list is also throwing a error i'd suspect after the parent is fixed

[JsonProperty(PropertyName = "products")]
[Column]

///设置已订购的产品列表

 public List<ProductsOrdered> Productsordered
{
get { return po; }
set
{
NotifyPropertyChanging("Products Ordered");
po = value;
NotifyPropertyChanged("Products Ordered");
}
}

[JsonProperty(PropertyName = "value")]
[Column]
public double totalprice
{
get { return TotalPrice; }
set {
NotifyPropertyChanging("Total Price");
TotalPrice = value;
NotifyPropertyChanged("Total Price");
}
}


[JsonProperty(PropertyName = "id")]
[Column(IsPrimaryKey = true, IsDbGenerated = false, AutoSync = AutoSync.OnInsert)]
public int customerid
{
get { return customer_id; }
set {
NotifyPropertyChanging("Customer_ID");
customer_id = value;
NotifyPropertyChanged("Custome_ID");

}
}



private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}

private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}


public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangingEventHandler PropertyChanging;
}

///错误源自的零售商订单 System.Data.Linq.dll 中发生类型为“System.InvalidOperationException”的未处理异常

  [Table]
public class RetailOrders : INotifyPropertyChanged, INotifyPropertyChanging
{
private List<OrderItems> oi;
private string retailer_id;
private DateTime date;


[Column(IsPrimaryKey = true, IsDbGenerated = false, AutoSync = AutoSync.OnInsert)]
[JsonProperty(PropertyName = "retailer_id")]
public string Retailer_id
{
get { return retailer_id; }
set {
NotifyPropertyChanging("Retailer ID");
retailer_id = value;
NotifyPropertyChanged("Retailer ID");
}
}

有关该错误的更多信息表明它起源于此处,无法确定“System.Collections.Generic.List`1[SalesManagement.OrderItems]”的 SQL 类型。这让我觉得我错误地设置了列值

        [JsonProperty(PropertyName = "orders")]
[Column]
public List<OrderItems> OrderItems
{
get { return oi; }
set {
NotifyPropertyChanging("OrderItems");
oi = value;
NotifyPropertyChanged("OrderItems");
}
}


[JsonProperty(PropertyName = "date")]
[Column]
public DateTime Date
{
get { return date; }
set {
NotifyPropertyChanging("date");
date = value;
NotifyPropertyChanged("date");
}
}



private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}

private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}


public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangingEventHandler PropertyChanging;
}

///这是我的产品订购表,其中包含一个具有 ID、质量和单价的对象

    [Table]
public class ProductsOrdered : INotifyPropertyChanged, INotifyPropertyChanging
{
private string productID;
private int quantity;
private double unit_price;



[JsonProperty(PropertyName = "product_id")]
[Column(IsPrimaryKey = true, IsDbGenerated = false, AutoSync = AutoSync.OnInsert)]
public string ProductID
{
get { return productID; }
set
{
NotifyPropertyChanging("product ID");
productID = value;
NotifyPropertyChanged("product ID");
}
}

[JsonProperty(PropertyName = "quantity")]
[Column]
public int Quantity
{
get { return quantity; }
set {
NotifyPropertyChanging("quantity");
quantity = value;
NotifyPropertyChanged("quantity");
}
}
[JsonProperty(PropertyName = "unit_price")]
[Column]
public double UnitPrice
{
get { return unit_price; }
set {
NotifyPropertyChanging("unit price");
unit_price = value;
NotifyPropertyChanged("unit price");
}
}



private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}

private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangingEventHandler PropertyChanging;
}

通过一些调查,它让我相信一旦进入列表就使用 [ASSOCIATION] 而不是 [Column] 但是我不确定处理表格的正确方法是什么

最佳答案

我认为您在尝试重用 JSON、MVVM 和 SQL 的类时混淆了问题。为序列化、 View 和实体设置不同(但最终非常相似)的类要好得多。

关于c# - 正确使用表中列值中的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54309142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com