Jonathan Pryor provò:
> > If no separate Storage is specified, directly set the Column
> > member, even if it is a writable property instead of a field.
> >
> > This is not needed for DbMetal-generated files, but should be generally
> > applicable when writing classes by hand.
> >
> > Perhaps this should be merged with the following patch, let me known or
> > apply directly as you prefer.
>
> This does not cleanly apply against DataContext.cs in trunk (r1218).
Mh, perhaps a CR/LF problem?
The attached patch has been generated with svn from r1221.
--
Emanuele Aina
Studio Associato Di Nunzio e Di Gregorio
http://dndg.it/
Via Maria Vittoria, 2
10123 Torino - Italy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: src/DbLinq/Data/Linq/DataContext.cs
===================================================================
--- src/DbLinq/Data/Linq/DataContext.cs (revisione 1221)
+++ src/DbLinq/Data/Linq/DataContext.cs (copia locale)
@@ -704,14 +704,27 @@
//it would be interesting surround the above query with a .Take(1) expression for performance.
}
+ // If no separate Storage is specified, use the member directly
+ MemberInfo storage = memberData.StorageMember;
+ if (storage == null)
+ storage = memberData.Member;
- FieldInfo entityRefField = (FieldInfo)memberData.StorageMember;
+ // Check that the storage is a field or a writable property
+ if (!(storage is FieldInfo) && !(storage is PropertyInfo && ((PropertyInfo)storage).CanWrite)) {
+ throw new InvalidOperationException(String.Format(
+ "Member {0}.{1} is not a field nor a writable property",
+ storage.DeclaringType, storage.Name));
+ }
+
+ Type storageType = storage.GetMemberType();
+
object entityRefValue = null;
if (query != null)
- entityRefValue = Activator.CreateInstance(entityRefField.FieldType, query);
+ entityRefValue = Activator.CreateInstance(storageType, query);
else
- entityRefValue = Activator.CreateInstance(entityRefField.FieldType);
- entityRefField.SetValue(entity, entityRefValue);
+ entityRefValue = Activator.CreateInstance(storageType);
+
+ storage.SetMemberValue(entity, entityRefValue);
}
}