Datacontext for custom string types RRS feed

  • Question

  • User-501461518 posted

    Hi. I have created a Linq to SQL datacontext. In one table I have a string field. However, the data in that field is a custom class (myString).

    I'd like to know what is the cleanest and most efficient way to have the datacontext with the field as type myString rather than string. I realise that the datacontext defines classes as partial classes. Thus I can add methods to the datacontext but that alone still means the field is a string. I would prefer not to try deriving a class. What are the options and any recommendation for the best option.

    myString has its own methods, validation and function.

    Thursday, May 21, 2015 2:50 PM


All replies

  • User-821857111 posted

     Linq to SQL is pretty much deprecated in favour of Entity Framework. However, if you want to know more about custom type mapping, this should help: https://msdn.microsoft.com/en-us/library/cc716764(v=vs.110).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 21, 2015 5:08 PM
  • User-501461518 posted

    Thanks. I didn't realise you could just change the datatype in the O/R designer to a custom type. Magic.

    I haven't used Entity Framework and this website has to be finished quickly and has been a very long journey. I'm therefore reluctant to learn a new framework but I'm in two minds. The site I am working on has a complex model so either EF will either make it much easier or more complicate and not knowing much about EF I'm not sure which,

    I really appreciate the help on the datatype question. Thanks

    Friday, May 22, 2015 6:52 AM