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.
In response to your comment on the question, the Linq-To-Sql classes are generated as partial. This means you can have separate code files with the same class names declared as partial to add the extra properties you want.
E.g. Your Ling-To-Sql designer class will be:
You can have your own separate file (in the same project) called Car.cs:
And the two classes will be merged together. Just make sure they are in the same namespace.