簡體   English   中英

在不使用poco類的情況下向實體添加屬性

[英]Adding properties to an entity without using poco classes

我有一個EF實體的實例,我將其序列化為JSON。 有沒有辦法為它添加一些屬性,而不使用POCO類? 也許創建一個新對象並附加它,如果可能的話?

HttpContext.Current.Response.Write(serializer.Serialize(system.OrderByDescending(s => s.SYSTEM_ID)));
HttpContext.Current.Response.Write(
    serializer.Serialize(
        system.OrderByDescending(s => s.SYSTEM_ID).Select(s => new {
            s.SYSTEM_ID,
            NewProperty = "Foo"
})));

我不知道你的代碼在哪里執行,但直接使用HttpContext Response.Write有點氣味。

EF生成的類是部分...

您可以添加一個附加文件,向其添加屬性和方法。

例如

public partial class MyEntity
// no need to specify base or interfaces as they are specified elsewhere
{
    // Add stuff here
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM