实体框架代码首先将基于模型在数据库基础中自动创建表.
是否有一个属性可以避免这种情况?
如何使用codefirst EF4创建非持久属性?
MS说有一个StoreIgnore属性,但我找不到它.
有没有办法使用EntityConfiguration设置它?
在我的Asp.NET MVC4应用程序中,我想在我的模型中添加一个字段而不将其添加到数据库中.
对仅存在于模型的c#实例中但不存在于数据库本身中的字段的排序.
是否有任何注释或其他方法从数据库本身中排除该字段?
我的意思是我可以在运行时读取和写入的对象,数据库不知道.
我想知道有没有办法从数据库中排除一些字段?例如:
public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string FatherName { get; set; }
    public bool IsMale { get; set; }
    public bool IsMarried { get; set; }
    public string AddressAs { get; set; }
}
如何从数据库中排除AddressAs字段?
我在SQL Server数据库的产品表中有一个图像列。image列用于将图像另存为字节。
我知道最好为图像创建一个单独的表格,但是我没有这样做,所以当我尝试仅列出不含图像的产品时,有什么方法可以排除图像列吗?
我将一个对象数组返回到一个页面,该页面基于相册呈现幻灯片.
我从数据库中取出我的照片.
因此,在我返回此数组之前,我想介绍一个"Thumbnail"url属性.AlbumPicture中不存在此属性,但我想在响应中使用它.
这说明了这个想法:
List<AlbumPicture> pics = db.AlbumPictures.Where(p => p.AlbumID == album.ID).OrderBy(p => p.RankOrder).ToList();
foreach(AlbumPicture p in pics)
{
    p.AddPropertyThatDoesntExist("Thumbnail", ThumbManager.GetThumb(p.ID));
}
return Json(pics, JsonRequestBehavior.AllowGet);
将此JSON字段添加到结果集的最优雅方法是什么?
这个问题非常基本,可能是重复的.但是,我用Google搜索了10分钟,只能找到依赖于第三方库的janky解决方案.我对目前的"最佳实践"感兴趣.
可能重复:如何从控制器向Json响应动态添加更多属性.但是,该答案将在生成的JSON中将动态添加的字段(而不是兄弟)添加到我的AlbumPicture属性中.
我有一个代码优先模型,其中所有实体都是从Entity基类派生的.我IsDeleted在基类中有一个属性,我想在所有实体中忽略(我不能删除/注释IsDeleted属性,因为在许多项目中使用了基类).有没有办法配置modelBuilder为从所有实体(通过约定,我认为)中忽略此属性,而不指定modelBuilder.Entity<...>().Ignore(l => l.IsDeleted)我的模型中的所有实体?
谢谢,离子
我通过脚本创建了我的数据库,然后使用 scaffold 命令在 Visual Studio 中创建了我的类,我为实体(用户)添加了一个新的部分类,每当我运行时,我在其中添加了一些自定义属性(这不会在数据库中)获取到此实体,它会为我在分部类中设置的每个自定义属性抛出错误无效的列名。
异常消息: 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; …我正在使用asp.net mvc-5 Web应用程序,我正在使用实体框架5.0.我已经映射了我创建.edmx文件的SQL服务器数据库表.现在我想扩展模型类以获得额外的非数据库属性,所以我为我的模型类创建了一个部分类,我提供了一个额外的属性如下: - 
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Test.Models
{
    public partial class User
    {
         [NotMapped]
         public string NonDataBaseColumn { set; get; }
    }
}
所以我有这些问题:
[NotMapped]数据注释,还是[NotMapped]仅在遵循代码优先方法时才有效?c# ×7
asp.net-mvc ×3
.net ×2
asp.net ×1
asp.net-core ×1
code-first ×1
conventions ×1
database ×1
edmx ×1
ignore ×1
json ×1
poco ×1
properties ×1