更改类属性名称EF [英] Change class property name EF

查看:104
本文介绍了更改类属性名称EF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

i想要更改EF Entity中的属性名称以使用Web Api创建Custome XML。

我的实体是

  public   partial   class  foo 
{
public int ID { get ; < span class =code-keyword> set ;}
public string 姓名{获取; set ;}
public string LastName { get ; set ;}
}

并创建Xml是

 <   foo  >  
< 名称 > Ali
< lastname > Shahmohammadi
< id > 1 < / id >
< / foo >

但我想拥有像

 <   foo  <的custome xml span class =code-keyword>>  
< firstname > Ali
< family > Shahmohammadi
< code > 1 < / code >
< / foo >





但我不想装饰我的实体foo类
i有一个类如
内部类FooMetaData
{
public int ID {get; set;}
public string Name {得到; set;}
public string LastName {get; set;}
}
和像
这样的部分类[MetadataType(typeof(FooMetaData))]
public partial class Foo
{

}

i希望将FooMetaData类装饰为custome xml





我尝试过:



学习

并创建Xml是

解决方案

你好,



你只需要装饰你的班级。



 [DataContract( Namespace =)] 
public partial class foo
{
[DataMember(Name =code)]
public int ID {get;组; }
[DataMember(Name =Firstname)]
public string Name {get;组; }
[DataMember(Name =Family)]
public string LastName {get;组; }
}





Valery。


我听说你不想用属性来装饰你的类,但是要完全用POCO来完成它,还需要做更多的工作。



查看Sam的Flickr.Net Lib。以下是他如何使用他的照片类: flickr-net / Photo.cs at master ·samjudson / flickr-net·GitHub [ ^ ]。



我的偏好不是Sam的方式,因为维护它比使用属性和允许序列化过程为你完成工作有更多的工作。

hi
i want change Property Name in EF Entity to create Custome XML with Web Api.
my entity is

public partial class foo
{
   public int ID{get;set;}
   public string Name{get; set;}
   public string LastName{get; set;}
}

and created Xml is

 <foo>
    <name>Ali
    <lastname>Shahmohammadi
    <id>1</id>
</foo>

but i want have custome xml like

 <foo>
    <firstname>Ali
    <family>Shahmohammadi
    <code>1</code>
</foo>



but i do not want decorate my entity foo class
i have a class like
internal class FooMetaData
{
public int ID{get;set;}
public string Name{get; set;}
public string LastName{get; set;}
}
and a partial class like
[MetadataType(typeof(FooMetaData))]
public partial class Foo
{

}

i want decorate FooMetaData Class to custome xml



What I have tried:

to learn
and created Xml is

解决方案

Hello,

You just need to decorate your class.

[DataContract(Namespace = "")]
public partial class foo
{
    [DataMember(Name = "code")]
    public int ID { get; set; }
    [DataMember(Name = "Firstname")]
    public string Name { get; set; }
    [DataMember(Name = "Family")]
    public string LastName { get; set; }
}



Valery.


I hear that you don't want to decorate your classes with attributes but to do it totally POCO, there is a bit more work involved.

Check out Sam's Flickr.Net Lib. Here is how he does it with his Photo Class: flickr-net/Photo.cs at master · samjudson/flickr-net · GitHub[^].

My preference is not to do it Sam's way as there is more work to maintain it than using attributes and allowing the serialization process to do the work for you.


这篇关于更改类属性名称EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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