小编Hel*_*ren的帖子

自动映射多对多映射

帕特里克,感谢有关正确问题的建议!

编辑1:

我有三张关于多对多关系的表.像这样: EF数据模型

GoodEntity:

public partial class GoodEntity
{
    public GoodEntity()
    {
        this.GoodsAndProviders = new HashSet<GoodAndProviderEntity>();
    }

    public int id { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public decimal cost { get; set; }
    public Nullable<decimal> price { get; set; }

    public virtual ICollection<GoodAndProviderEntity> GoodsAndProviders { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

ProviderEntity:

public partial class ProviderEntity
{
    public ProviderEntity()
    {
        this.GoodsAndProviders = new HashSet<GoodAndProviderEntity>();
    }

    public int id { get; …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework automapper

7
推荐指数
1
解决办法
9567
查看次数

Kotlin:如何使用索引从特定位置迭代集合(跳过带有索引的 N 个元素)

我想从特定位置迭代项目集合。假设我们想从中心开始迭代数组的整个右侧部分:

int startFrom = arr.length / 2;
for (int i = startFrom; i < arr.length; i++)
{
    String.format("Index %d value %s", i, arr[i]);
}
Run Code Online (Sandbox Code Playgroud)

在迭代过程中跟踪真实的索引和值非常重要。作为示例,您将实现就地排序算法

我尝试使用 drop().withIndexes() 来执行此操作,但看起来 drop() 创建了一个新集合,并且我丢失了有关真实索引的信息。如果我们创建一个变量并计算适当的索引,则可以手动修复它

val startFrom = inputData.size / 2
for ((i, item) in inputData.drop(startFrom).withIndex()){
    val fixedIndex = i + startFrom
    println("Index $i, fixed index $fixedIndex value $item")
}
Run Code Online (Sandbox Code Playgroud)

这个解决方案有效,但我希望有一些东西可以帮助避免引入单独的固定索引变量并手动处理这个问题。

kotlin

0
推荐指数
1
解决办法
1379
查看次数

标签 统计

.net ×1

automapper ×1

c# ×1

entity-framework ×1

kotlin ×1