ASP.NET Entity Framework在生成视图时隐藏模型属性
创始人
2024-09-16 06:00:25
0

要在生成视图时隐藏模型属性,可以使用数据注解或Fluent API来配置实体属性。

使用数据注解:

using System.ComponentModel.DataAnnotations.Schema;

public class MyEntity
{
    public int Id { get; set; }

    [NotMapped]
    public string HiddenProperty { get; set; }

    public string VisibleProperty { get; set; }
}

使用Fluent API:

using System.Data.Entity.ModelConfiguration;

public class MyEntityConfiguration : EntityTypeConfiguration
{
    public MyEntityConfiguration()
    {
        Ignore(e => e.HiddenProperty);
    }
}

然后,在DbContext的OnModelCreating方法中应用配置:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Configurations.Add(new MyEntityConfiguration());
}

这样,当生成视图时,HiddenProperty属性将被忽略,不会出现在生成的视图中。

相关内容

热门资讯

透视黑科技!wepoker私人... 透视黑科技!wepoker私人定制透视(透视)天酷辅助器(本来有辅助工具)-哔哩哔哩该软件可以轻松地...
针对!hh poker透视器下... 针对!hh poker透视器下载(透视)福建789大菠萝脚本(真是真的有辅助平台)-哔哩哔哩1、福建...
透视美元局!agpoker辅助... 透视美元局!agpoker辅助(透视)途游手游辅助(确实真的是有辅助下载)-哔哩哔哩该软件可以轻松地...
今日!hhpoker德州有挂吗... 今日!hhpoker德州有挂吗(透视)潮友会鱼虾蟹有没有挂辅助(好像真的有辅助插件)-哔哩哔哩;暗藏...
不少玩家反映!aapoker万... 不少玩家反映!aapoker万能辅助器(透视)拼十app辅助(果然真的是有辅助辅助器)-哔哩哔哩进入...
近日!wpk透视是真的假的(透... 近日!wpk透视是真的假的(透视)哈糖大菠萝可以开挂吗(确实是有辅助下载)-哔哩哔哩1、用户打开应用...
网友热议!wepokerplu... 网友热议!wepokerplus脚本(透视)方片十三张外卦(本来存在有辅助软件)-哔哩哔哩1、首先打...
今天上午!wepoker私人局... 今天上午!wepoker私人局辅助(透视)中至余干510k开挂(都是真的有辅助修改器)-哔哩哔哩1、...
有消息称!拱趴大菠萝挂哪里(透... 有消息称!拱趴大菠萝挂哪里(透视)微信边锋辅助下载(其实真的是有辅助下载)-哔哩哔哩1、微信边锋辅助...
透视最新!hhpoker透视脚... 透视最新!hhpoker透视脚本视频(透视)约战平台辅助(总是真的有辅助平台)-哔哩哔哩1、约战平台...