首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ICollections<Float>中使用映射器

如何在ICollections<Float>中使用映射器
EN

Stack Overflow用户
提问于 2015-02-18 22:35:59
回答 1查看 65关注 0票数 1

我想知道如何使用mapper类将集合存储到数据库中。

类型'System.Collections.Generic.ICollection‘必须是非空值类型,才能将其用作泛型类型或方法System.Collections.Generic.ICollection中的参数'T’。

我的地图班

代码语言:javascript
复制
            public LocatieMapper()
    {
        //Table
        this.ToTable("Locatie");

        //Properties => Columns
        this.Property(p => p.Naam);
        this.Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        this.Property(p => p.GemiddeldeMaandTemperaturen).IsRequired();

        //Primary Key
        this.HasKey(k => k.Id);

        //Relationships

    }
}
}

这是我的本地班

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Klimatogrammen.Models.Domain
{
public class Locatie
{
    [Key]
    public int Id { get; set; }
    private String naam;
    private ICollection<float> gemiddeldeMaandTemperaturen;//want to map this
    private ICollection<float> totaleMaandNeerslag;//and this 

    public Locatie(String naam, ICollection<float> gemiddeldeMaandTemperaturen, ICollection<float> totaleMaandNeerslag)
    {

        this.Naam = naam;
        // test

        this.GemiddeldeMaandTemperaturen = gemiddeldeMaandTemperaturen;
        this.TotaleMaandNeerslag = totaleMaandNeerslag;
    }
// other code 

添加构造器以获取额外信息

调用构造函数示例

代码语言:javascript
复制
    temperatuur = new List<float> { 3.46F, 3.8F, 6.65F, 9.25F, 12.95F, 15.35F, 17.75F, 17.6F, 14.8F, 11.2F, 7F, 4.05F };
        neerslag = new List<float> { 60.5F, 63F, 56.3F, 42.4F, 59.7F, 60F, 77.3F, 88.4F, 73.7F, 68.3F, 80.9F, 82.5F };
        Locatie gent = new Locatie("Gent", temperatuur, neerslag);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-18 22:48:11

您的问题是您使用的是StructuralTypeConfiguration,因此属性方法需要一个表达式来描述返回值类型的函数。ICollection<T>不是值类型(实际上,所有接口类型都是引用类型)。

尝试使用ConventionTypeConfiguration代替。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28595333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档