开发者

LINQ to SQL table naming

开发者 https://www.devze.com 2022-12-29 15:10 出处:网络
I am using VS2010 and C# When I map/select my database tables with LINQ to SQL I have to option to change the \"member\" propery, but when i delete the 开发者_JAVA百科table (because I changed somethi

I am using VS2010 and C#

When I map/select my database tables with LINQ to SQL I have to option to change the "member" propery, but when i delete the 开发者_JAVA百科table (because I changed something in the schema for example) and add it again the member value gets "reset". Is it possible to set/override this member programmaticly, so that I dont have to change it by hand everytime

I mean the member option of

'<'Table Name="dbo.table1" Member="table1">


All L2S ORM classes are partial, so you should be able to encapsulate the table in another property by extending the DataContext class e.g.

public partial class MyDataContext
{
    public IEnumerable<Entity> Table
    {
        get { return DatabaseTable; }
    }
}

So in the above scenario you would make your DatabaseTable private and expose it through a another property. You may still need to change that particular piece of code manually if you change the name of your table, but it means you are only changing it once and don't have to change it everytime you reference the table somewhere in your code.

0

精彩评论

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

关注公众号