> Possible. Not great though - it looks like parameter names are
> preserved even for release builds, but I don't know if that's
> guaranteed.
> > Possible. Not great though - it looks like parameter names are
> > preserved even for release builds, but I don't know if that's
[quoted text clipped - 5 lines]
>
> So parameter name saving *is* guaranteed.
Right. In that case, that's not a *hugely* bad way round it.
> > What makes you think LINQ to SQL has this issue to start with?
>
> Linq-SQL generated entity class code has probably full parameter
> constructors.
No, it doesn't. I've just checked.
> To instantiate entity objects, Linq-SQL driver must convert columns returned
> from SQL SELECT command to constructor parameters.
No, it doesn't. I don't know exactly what it *does* do (it seems to
avoid properties too) but there's no constructor with parameters for it
to call.
> > Why do you have this issue in the first place? Are the objects
> > immutable? If not, can't you just set the properties directly?
>
> I'm trying to fix DbLinq driver code.
> Linq driver does not know property names and even entity type names.
> All information must be determined at runtime.
None of that stops you from setting properties.
> I have found also two additional ways:
>
> 1. Set every property separately, remove parametherized constructor.
> 2. Sort constructor parameters in alphabetical order.
>
> Really do'nt know which is the best way to go so trying this dirty hack.
Setting properties is by far the cleanest way here, IMO.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Andrus - 06 Jan 2008 09:50 GMT
>> So parameter name saving *is* guaranteed.
>Right. In that case, that's not a *hugely* bad way round it.
I subclass entity base classes to add custom properties by compiling
assembly at runtime.
I need also to add business methods like
public static Customer FindById(string id) {
var q = (from k in Default.Db.Customers
where k.Id == id
select k).SingleOrDefault();
return q;
}
to those dynamic-subclassed entities at design time.
At design time I do'nt know all Customer properties. So I cannot create cs
file containing full-property constructor and thus cannot use subclassing.
Partial assemblies are not supported in .net. Using partial classes requires
compiling business method source code at runtime. This seems not reasonable.
So Adding FindById() to full-parameter constructor class requires creating
separate not-inherited business logic class for every entity. This makes
application unnessecarily complicated.
Is this reasonable ?
> No, it doesn't. I don't know exactly what it *does* do (it seems to
> avoid properties too) but there's no constructor with parameters for it
> to call.
Let's say we have
Db.Customers.ToList()
expression.
Linq-SQL driver must use GetProperties() to find all Customer properties
having ColumnAttribute attributes.
Then it should invoke parameteless constructor to create new Customer entity
and use reflection to set new entity properties, one-by-one.
I see no other way.
However in my case this requires re-writing parts of DbLinq driver code.
> Setting properties is by far the cleanest way here, IMO.
I'm in initial stage of development called "probing".
I do'nt have enough resources required to re-write, debug and support
property approach in this stage.
I'm planning to create application quick prototype.
Results of this probe determine will we move to .NET or start looking
something other.
So creating separate business classes for every entity class and using quick
dirty hack to fix
GetProperties() ordering issue seems to be optimal in this case, is'nt it ?
Andrus.
Jon Skeet [C# MVP] - 06 Jan 2008 12:45 GMT
> >> So parameter name saving *is* guaranteed.
> >Right. In that case, that's not a *hugely* bad way round it.
[quoted text clipped - 14 lines]
> At design time I do'nt know all Customer properties. So I cannot create cs
> file containing full-property constructor and thus cannot use subclassing.
To be honest, despite your explanations it's still not at all clear
what you're trying to do. However, it's equally unclear why you're
holding on to this "full-parameter constructor" idea despite it clearly
having issues, when setting properties would appear to be a lot
simpler.
> > No, it doesn't. I don't know exactly what it *does* do (it seems to
> > avoid properties too) but there's no constructor with parameters for it
[quoted text clipped - 11 lines]
> and use reflection to set new entity properties, one-by-one.
> I see no other way.
I've just had a closer look, and it uses the Storage property of the
Column attribute applied to the relevant property, then sets the field
directly (presumably with reflection).
> However in my case this requires re-writing parts of DbLinq driver code.
>
[quoted text clipped - 11 lines]
> dirty hack to fix
> GetProperties() ordering issue seems to be optimal in this case, is'nt it ?
Not if the point is to see whether it's suitable for production use -
using a technique which you know shouldn't be used for production seems
like a bad idea to me.
Using the parameter names is more reasonable, however.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk