[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

c# Entity Framework ModelFirst DataType

Using visualStudio 2010 I'm modelling a db.
From the designer I've added a codeGeneration item.
So now I have a MyModel.tt file, with all my .cs file under.

But I need to customize the .cs files.
Lets say the file created using the MyModel.tt looks like this:
namespace TestingDB
{
    using System;
    using System.Collections.Generic;
   
    public partial class Menu
    {    
        public int Id { get; set; }
        public string Name{ get; set; }
     }
}

I need it to look like this:
namespace TestingDB
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
   
    public partial class Menu
    {    
        public int Id { get; set; }
        [DataType(DataType.MultilineText)]
        public string Name{ get; set; }
     }
}

Now changing my MyModel.tt -> Menu.cs file works..
Untill I update something in the model. Then MyModel.tt regenerates the file, and all my customization is gone.


Any idea how i can do customization so it stays after changes in the model?
0
kristian_gr
Asked:
kristian_gr
  • 2
1 Solution
 
dj_alikCommented:
0
 
dj_alikCommented:
Example
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;

[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{


}


public class CustomerMetaData
{
    // Apply RequiredAttribute
    [Required(ErrorMessage = "Title is required.")]
    public object Title;


}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now