为一个属性设置多个值

发布于 2025-01-11 08:06:50 字数 884 浏览 0 评论 0原文

我有两个类,您可以在下面看到:

public class Product
{
    public int Id {get; set;}
    public string Name {get; set;}
    public decimal SuggestionPrice {get; set;}
    public List<SaleOrder> SaleOrders {get; set;} = new List<SaleOrder>();

}
public class SaleOrder
{
    public int Id {get; set;}
    public List<Product> Products {get; set;} = new List<Product>();
}

如您所见,这两个类具有 Many-To-Many RealationShip to everyother.in Product class 我有 我想在其中保存多个值 SuggestionPrice 属性,并且每个 SaleOrder 类 都有所不同。

例如,某人在一个 SaleOrder 中提供 1,000 美元,而其他人在另一个 SaleOrder 中针对相同产品提供 2,000 美元,以及我想要的无数其他建议将它们全部保存在数据库中

问题是我不知道该怎么做?我怎么知道女巫 SuggestionPrice 是女巫 SaleOrder Class 的?

I have two class that you can see below:

public class Product
{
    public int Id {get; set;}
    public string Name {get; set;}
    public decimal SuggestionPrice {get; set;}
    public List<SaleOrder> SaleOrders {get; set;} = new List<SaleOrder>();

}
public class SaleOrder
{
    public int Id {get; set;}
    public List<Product> Products {get; set;} = new List<Product>();
}

as you can see,this two class have Many-To-Many RealationShip to eachother.in Product class i have SuggestionPrice property that i want save multiple value in it and it's difference for each SaleOrder Class.

for example,Someone offers $ 1,000 in one SaleOrder and someone else offers $ 2,000 in another SaleOrder for same product and infinitely another suggestions that I want to save them all in database.

problem is i don't know how can i do this?how can i know witch SuggestionPrice is for witch SaleOrder Class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腻橙味 2025-01-18 08:06:50

要保存在数据库中,您应该创建一个如下所示的 SuggestionPrice 表:

public class SuggestionPrice
{
public int Id {get;set}
public int ProductId {get;set;}
public decimal Price {get;set;}
public Product Product {get;set;}
}

并将产品类更改为:

public class Product
{
    public int Id {get; set;}
    public string Name {get; set;}
    public ICollection<SuggestionPrice> SuggestionPrices {get; set;}
}

在 Product 和 SuggestionPrice 之间创建一对多关系。

To save in database You should create a SuggestionPrice table like this:

public class SuggestionPrice
{
public int Id {get;set}
public int ProductId {get;set;}
public decimal Price {get;set;}
public Product Product {get;set;}
}

and change product class to this:

public class Product
{
    public int Id {get; set;}
    public string Name {get; set;}
    public ICollection<SuggestionPrice> SuggestionPrices {get; set;}
}

to create a one to many relation between Product and SuggestionPrice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文