Prevent compiler to stop undo my changes in T4 classes Entity Framework
up vote
0
down vote
favorite
I am using Entity Framework and want to do some changes in context class
For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx
file and save it, then my changes are no longer exist.
Is there any way for me to tell .edmx
not to undo my changes in context class or T4 classes?
entity-framework t4
add a comment |
up vote
0
down vote
favorite
I am using Entity Framework and want to do some changes in context class
For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx
file and save it, then my changes are no longer exist.
Is there any way for me to tell .edmx
not to undo my changes in context class or T4 classes?
entity-framework t4
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using Entity Framework and want to do some changes in context class
For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx
file and save it, then my changes are no longer exist.
Is there any way for me to tell .edmx
not to undo my changes in context class or T4 classes?
entity-framework t4
I am using Entity Framework and want to do some changes in context class
For ex. I am creating one more constructor for connection string but issue is every time when I open .edmx
file and save it, then my changes are no longer exist.
Is there any way for me to tell .edmx
not to undo my changes in context class or T4 classes?
entity-framework t4
entity-framework t4
edited Nov 19 at 16:14
Cœur
17k9102140
17k9102140
asked Mar 31 '15 at 5:10
Parveen
2261218
2261218
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.
Add your additions to a separate file containing the custom part of the partial class.
See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
add a comment |
up vote
0
down vote
An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.
Another alternative is to take full control of the classes by using code first.
You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs
I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.
The answer of Maarten is also fine, but there are 2 more options.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.
Add your additions to a separate file containing the custom part of the partial class.
See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
add a comment |
up vote
5
down vote
You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.
Add your additions to a separate file containing the custom part of the partial class.
See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
add a comment |
up vote
5
down vote
up vote
5
down vote
You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.
Add your additions to a separate file containing the custom part of the partial class.
See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx
You cannot change the generated code. You can add things to it since the classes that are generated are partial classes.
Add your additions to a separate file containing the custom part of the partial class.
See here: https://msdn.microsoft.com/en-us/library/wa80x488.aspx
answered Mar 31 '15 at 5:12
Maarten
18.5k33354
18.5k33354
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
add a comment |
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
Thanks alot . It is very helpful.
– Parveen
Mar 31 '15 at 5:21
add a comment |
up vote
0
down vote
An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.
Another alternative is to take full control of the classes by using code first.
You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs
I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.
The answer of Maarten is also fine, but there are 2 more options.
add a comment |
up vote
0
down vote
An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.
Another alternative is to take full control of the classes by using code first.
You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs
I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.
The answer of Maarten is also fine, but there are 2 more options.
add a comment |
up vote
0
down vote
up vote
0
down vote
An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.
Another alternative is to take full control of the classes by using code first.
You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs
I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.
The answer of Maarten is also fine, but there are 2 more options.
An alternative is to modify the T4 template yourself and consistently apply your specific needs to the generated classes.
It is common practice to do this when for example you want INotifyPropertyChanged as interface on every class.
This approach only works if your changes are generic in nature. If you want to do a specific change in only one class then this solution does not work for you.
Another alternative is to take full control of the classes by using code first.
You can mark the methods and properties with special attributes to map them to the db. And there is a reverse engineering option to create these classes from an existing db. You would reverse engineer once, and then take control of the classes and tweak them to your needs
I generally take the last approach myself right now, because it is not using partial classes all code that belongs to a class is all in the same file.
The answer of Maarten is also fine, but there are 2 more options.
answered Mar 31 '15 at 6:53
Philip Stuyck
6,14131733
6,14131733
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29361008%2fprevent-compiler-to-stop-undo-my-changes-in-t4-classes-entity-framework%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown