How can I extend a LINQ-to-SQL class without having to make changes every time the code is generated

Posted by csharpnoob on Stack Overflow See other posts from Stack Overflow or by csharpnoob
Published on 2010-05-10T10:43:09Z Indexed on 2010/05/10 13:34 UTC
Read the original article Hit count: 223

Filed under:
|
|
|

Hi,


Update from comment:

I need to extend linq-to-sql classes by own parameters and dont want to touch any generated classes. Any better suggestes are welcome. But I also don't want to do all attributes assignments all time again if the linq-to-sql classes are changing. so if vstudio generates new attribute to a class i have my own extended attributes kept separate, and the new innerited from the class itself


Original question:

i'm not sure if it's possible. I have a class car and a class mycar extended from class car. Class mycar has also a string list. Only difference.

How can i cast now any car object to a mycar object without assigning all attributes each by hand. Like:

Car car = new Car();

MyCar mcar = (MyCar) car;

or

MyCar mcar = new MyCar(car);

or however i can extend car with own variables and don't have to do always

Car car = new Car();
MyCar mcar = new MyCar();
mcar.name = car.name;
mcar.xyz = car.xyz;
...

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about casting