I often take the classes that linq2sql generates and create a simple data-only class like so
public class myentity
{
public Guid id { get; set; }
public string name { get; set; }
// etc
}
I don't put methods in these classes and I mainly use them as helper classes so I can serialize to/from json and other similar actions, quite easily.
My question is, should I use a struct in this case rather than a class?
It seems to make sense to make it a struct as its more or less the definition of a struct, but I dont know if the performance will be ideal here since I often pass the classes around from method to method and I don't want a ton of copies since structs are value types.
Another thing I do quite often is use Linq2Sql's delayed execution to return my own lightweight version of the Linq2Sql classes, rather than the one they generate. I'm not entirely sure if using a struct instead of a class would have some adverse performance impact here.
an example of how I'd use delayed execution is something like this
public IEnumerable<myentity> getEntities()
{
return from me in MyEntity return new myentity() { id = me.id, name = me.name };
}
public IEnumerable<myentity> getEntitiesThatStartWith(string s)
{
return from me in getEntities() where me.name.StartsWith(s);
}