Organize EDMX Classes

2

I have a DB First project that uses an EDMX to map the database. The tables have standard columns that exist in all of them and I could organize and leave the code much more generic if I could implement interfaces in it with these properties, but it is not a good practice to change the classes automatically generated by EDMX. >

Is there a good practice or standard to improve the organization and reuse of code in the DB First model?

Update

Seeing that there is apparently no direct solution to this problem, is there any way, then, to get a code started with CodeFirst to automatically change with some change in the database? (import the modifications)?

    
asked by anonymous 30.09.2016 / 21:25

1 answer

0

I found that the solution is simpler than I expected.

//Classe gerada automaticamente pelo EF
public partial class BaseClassPartialTests
{
    public string PropTeste1 { get; set; }
    public string PropTeste2 { get; set; }
    public string PropTeste3 { get; set; }
}

//Como a classe gerada pelo EF é uma Partial Class, 
//basta criar, em outro arquivo, uma outra classe parcial herdando da interface que eu quero.
public partial class BaseClassPartialTests : IBaseProps
{
    public BaseClassPartialTests()
    {
        PropTeste1 = PropTeste2 = PropTeste3 = string.Empty;
    }
}

//Interface para aplicar nas classes.
public interface IBaseProps
{
    string PropTeste1 { get; set; }
    string PropTeste2 { get; set; }
}

The downside is that I will have to create a partial class for each class automatically generated by EF, but by applying the interface on them, it will make it possible to leave all my data access codes far more generic and less repetitive. Even with the possibility of building builders.

    
24.10.2016 / 16:04