zoukankan      html  css  js  c++  java
  • .netcore下EF model没有NotMapped

    NotMapped特性可以应用到EF实体类的属性中,如果类属性对应的库字段没有的,可以添加类属性标签[NotMapped],否则出现以下错误:

    Unknown column ‘字段名‘ in ‘field list‘ 错误

    在.netcore下找不到上述标签是因为 在程序集中要using System.ComponentModel.DataAnnotations.Schema

    而这个命名空间在 EntityFramework.dll中 ,没有在System.ComponentModel.DataAnnotations这个dll中

    解决办法:

    1、可以在库中添加此字段。

    2、不想在库中添加新字段,可以在DbContext的OnModelCreating方法重载中实现

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<BlogArticle>(entity =>
        {
            //不映射到数据库中
            entity.Ignore(p => p.Title);
        });
    }

     

  • 相关阅读:
    EFCore数据库迁移命令
    EF基本操作
    EF执行存储过程
    [vue]element-ui使用
    [vue]vue-router的使用
    [vue]使用webpack打包
    [vue]插槽与自定义事件
    [vue]计算属性
    [vue]axios异步通信
    [vue]组件
  • 原文地址:https://www.cnblogs.com/lunawzh/p/14777438.html
Copyright © 2011-2022 走看看