局部类中的自定义属性(无效的列名称) - c#

我通过脚本创建了数据库,然后使用scaffold命令在Visual Studio中创建了我的类,我为实体(用户)添加了新的部分类,并在其中每次运行时都添加了一些自定义属性(该属性不会出现在数据库中) a转到该实体,它将为我在我的局部类中设置的每个自定义属性引发错误的无效列名。

异常消息:
SqlException:无效的列名称'ResidentialName'。
无效的列名“ UserDocumentCount”。
无效的列名称“ UserPaymentCount”。

从数据库创建的局部类。

public partial class User
    {
        public User()
        {
            UserDocument = new HashSet<UserDocument>();
            UserPayment = new HashSet<UserPayment>();
        }

        public int UserId { get; set; }
        public string UserIdentityId { get; set; }
        public int? ResidentialId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public string Telephone { get; set; }
        public string Street { get; set; }
        public string Number { get; set; }
        public int Block { get; set; }
        public int Lot { get; set; }
        public bool Status { get; set; }
        public DateTime RegistrationDate { get; set; }

        public Residential Residential { get; set; }
        public AspNetUsers UserIdentity { get; set; }
        public ICollection<UserDocument> UserDocument { get; set; }
        public ICollection<UserPayment> UserPayment { get; set; }
    }

我添加的局部类。

public partial class User
    {
        public string ResidentialName { get { return this.ResidentialId > 0 && this.Residential != null ? this.Residential.Name : String.Empty; } set { } }
        public int UserDocumentCount { get { return this.UserDocument != null ? this.UserDocument.Count : 0; } set { } }
        public int UserPaymentCount { get { return this.UserPayment != null ? this.UserPayment.Count : 0; } set { } }

        public static async Task<List<User>> GetList(KaiozamaDevContext ctx)
        {
            return await ctx.User.ToListAsync();
        }
        public static async Task<User> GetItem(KaiozamaDevContext ctx, int Id)
        {
            return await ctx.User.SingleOrDefaultAsync(m => m.UserId == Id);
        }
        public static async Task<User> GetItem(KaiozamaDevContext ctx, string Id)
        {
            return await ctx.User.SingleOrDefaultAsync(m => m.UserIdentityId == Id);
        }
    }

从上面的任何Get方法上都会引发该错误。

问候!

更多技术细节

EF Core版本:2.1.0

数据库提供程序:Microsoft.EntityFrameworkCore.SqlServer

作业系统:Windows 10

IDE:Visual Studio社区2017 15.4.1

参考方案

将NotMapped属性添加到不在数据库中的属性中。

[NotMapped]
public string ResidentialName { get { return this.ResidentialId > 0 && this.Residential != null ? this.Residential.Name : String.Empty; } set { } }
[NotMapped]
public int UserDocumentCount { get { return this.UserDocument != null ? this.UserDocument.Count : 0; } set { } }
[NotMapped]
public int UserPaymentCount { get { return this.UserPayment != null ? this.UserPayment.Count : 0; } set { } }

从列表中获取价值(C#UWP) - c#

我有课 public class RootObject { public int id { get; set; } public int parent_id { get; set; } public string status { get; set; } public string order_key { get; set; } public string …

.get()之后,多处理陷入困境 - python

我试图了解multiprocessing如何在python中工作并遇到一些问题。这是示例:import multiprocessing def func(): return 1 p = multiprocessing.Pool() result = p.apply_async(func).get() 调用.get()函数时,代码只是卡住了。我究竟做错了什么?…

如何更改类的构造函数以接收已创建的类和构造函数的对象的通用列表? (C#) - c#

我有以下课程:public class OrderArticlesAdapter : RecyclerView.Adapter { public List<OrderArticleViewModel> listOfOrderArticles; ..... ..... //constructor public OrderArticlesAdapte…

AJAX和file_get_contents - php

我有一个使用file_get_contents的脚本,然后解码返回的JSON ...$urlone = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=f…

使用Json将具有两个对象的viewmodel传递给控制器 - c#

这是我的代码。下面的JSON不正确,但我想我很接近。控制器每次都获取空数据。任何帮助,将不胜感激。 $( "#btnRegister" ).click(function() { var personModel = { FirstName: $("#txtFirstName").val(), LastName: $(&#…