将自定义属性添加到客户端实体类 [英] Adding custom property to Client Side Entity class

查看:75
本文介绍了将自定义属性添加到客户端实体类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向Entity Framework类添加自定义属性,但是当我这样做时,我得到为类型XXX指定的属性名称XXX无效."错误.我可以给该属性提供一些属性,以便将其忽略并且不映射到任何东西吗?

I need to add a custom property to an Entity Framework class, however when I do I get the "The property name XXX specified for type XXX is not valid." error. Is there some attribute I can give the property so it is ignored and not mapped to anything?

如果我添加一个自定义属性(如下面的马丁示例所示),则以下代码将在SaveChanges调用中引发上述错误.

If I add a custom property, as per Martin's example below, then the following code will raise the above error at the SaveChanges call.

MyEntities svc = new MyEntities(url);
MyEntity ent = new MyEntity();
ent.MyField = "Hello, world";
svc.AddMyEntity(ent);
svc.SaveChanges();

推荐答案

以下是答案:更好的链接描述了添加属性以防止实体在发送到服务时序列化的最终简洁答案.

A better link describes the final compact answer of Adding an Attribute to prevent serialization of the Entity when sending to the Service.

这篇关于将自定义属性添加到客户端实体类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆