开发者

ADO.NET Entity Data Model - Adding custom properties

开发者 https://www.devze.com 2022-12-17 11:40 出处:网络
I am new to using the ADO.NET Entity Data Model tool. I 开发者_如何学JAVAhave a table in my database that has three properties (FirstName, LastName, Age). I need to add a field to this entity called I

I am new to using the ADO.NET Entity Data Model tool. I 开发者_如何学JAVAhave a table in my database that has three properties (FirstName, LastName, Age). I need to add a field to this entity called IsChosen. However, I cannot add this column in the database.

How do I add custom properties to entities generated through this tool?

Thank you!


The Entity Data Model tool creates partial classes.

You can extend those partial classes in another source file. You just need to make sure your section of the partial class lives in the same namespace as the Entity Data Model generated classes. For example:

Tool Generated Code

namespace Your.Generated.Classes
{
    public partial class Stuff
    {
        public string Name {get; set;}
        public int Age {get; set;}
    }
}

Your Seperate Code File

namespace Your.Generated.Classes
{
    public partial class Stuff
    {
        public string NonDatabaseProperty {get; set;}
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消