gpt4 book ai didi

c# - 如何处理旋转 POCO?

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

我有一个基于规范化表的 POCO。我的问题是如何处理将这个未旋转/规范化的对象更改为非规范化/旋转的对象?我是否需要创建另一个作为旋转版本的 POCO?如何处理这个问题?

假设标准化的 POCO 定义为:

客户表

CustomerId int
BestSeller bool
NumberOfOrders int

我想将其表示为

透视客户表

CustomerId int
BestSellerOrders int
NotBestSellerOrders int

更新

这有效,但不确定我是否喜欢它:

public void UpdateCustomer(CustomerPivot customerPivot)
{
using (var context = DataObjectFactory.CreateContext())
{
// find all the rows to update (2)
var rowsToUpdate = context.Customer
.Where(w => w.CustomerId == customerPivot.CustomerId).ToList();

var first = rowsToUpdate.Where(w => w.BestSeller == true).SingleOrDefault();
var second = rowsToUpdate.Where(w => w.BestSeller == false).SingleOrDefault();
first.NumberOfOrders = (int)customerPivot.BestSellerOrders;
second.NumberOfOrders = (int)customerPivot.NotBestSellerOrders;

context.Customer.ApplyChanges(first);
context.Customer.ApplyChanges(second);
context.SaveChanges();
}
}

最佳答案

是的,这是一个新的只读实体,映射到定义透视查询的数据库 View ,或者可能用作 ExecuteStoreQuery 执行的自定义 SQL 查询的物化结果的新自定义对象,因为在 SQL Server 中使用透视更容易并且更快。

关于c# - 如何处理旋转 POCO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5627760/

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