I have made a model with database first. I think this is very strange.
My Models are not in models folder, they are in a folder siteModel.tt and this folder is under sitemodel.edmx. Is this correct?
Also when I try to change the model it will go back to the way it was before. I noticed that it is partial classes so I maybe can add partial classes to my model folder? If I can, is there anybody that can explain to me how to do this?
Don't modify the classes generated by tt otherwise you'll lose your changes on updating edmx from database. Create separate partial class to override the behaviors.
With MVC applications, you are not required to use the Models folder. This is merely to help with organizing your model files.
Also, you do not have extra folders; with EF 5.0, your EDMX file is associated with a set of TT (text template) files along with your code file. The Solution Explorer is showing the file association through the hierarchy of the files.
As for adding custom partial classes to your model, there should be no issues with this; however, you probably want to move your EF files into the Models folder as well.
Christopher Reed, MCT, MCPD, MCTS, Microsoft Specialist, MTA
"The oxen are slow, but the earth is patient."
I got this working now. But I really want to have my partal classes in my models folder. If I store them in the models folder they will belong to another namespace and as I understand so must partial classes be in the same namespace.
I have changed the namspace in my partial class in the models folder so it work, is it ok to do that?
let say the namespace in my models folder is mySite.models, now I hav changed it to only mySite and it works fine.
svetsarn
Member
487 Points
612 Posts
Problem with model efter database first
Dec 25, 2012 11:34 AM|LINK
I have made a model with database first. I think this is very strange.
My Models are not in models folder, they are in a folder siteModel.tt and this folder is under sitemodel.edmx. Is this correct?
Also when I try to change the model it will go back to the way it was before. I noticed that it is partial classes so I maybe can add partial classes to my model folder? If I can, is there anybody that can explain to me how to do this?
urenjoy
Star
12347 Points
1857 Posts
Re: Problem with model efter database first
Dec 25, 2012 12:01 PM|LINK
Don't modify the classes generated by tt otherwise you'll lose your changes on updating edmx from database. Create separate partial class to override the behaviors.
have a look at following:
http://stackoverflow.com/questions/10118042/modify-model-structure-without-changing-existing-ef-4-x-generated-model-in-datab
Careed
All-Star
18774 Points
3637 Posts
Re: Problem with model efter database first
Dec 25, 2012 01:50 PM|LINK
With MVC applications, you are not required to use the Models folder. This is merely to help with organizing your model files.
Also, you do not have extra folders; with EF 5.0, your EDMX file is associated with a set of TT (text template) files along with your code file. The Solution Explorer is showing the file association through the hierarchy of the files.
As for adding custom partial classes to your model, there should be no issues with this; however, you probably want to move your EF files into the Models folder as well.
"The oxen are slow, but the earth is patient."
svetsarn
Member
487 Points
612 Posts
Re: Problem with model efter database first
Dec 26, 2012 09:09 AM|LINK
I got this working now. But I really want to have my partal classes in my models folder. If I store them in the models folder they will belong to another namespace and as I understand so must partial classes be in the same namespace.
I have changed the namspace in my partial class in the models folder so it work, is it ok to do that?
let say the namespace in my models folder is mySite.models, now I hav changed it to only mySite and it works fine.