Hello,
I had the same problem descriped in Issue 249. So I created a patch
that is working for me. It's not realy pretty but it's working. Maybe
someone has a better Idea how to fix this or can integrate this in the
production code. I also removed the schema name from the table name. A
thing I always had to do manualy.
Index: CodeDomGenerator.cs
===================================================================
--- CodeDomGenerator.cs (revision 1411)
+++ CodeDomGenerator.cs (working copy)
@@ -639,8 +638,8 @@
Name =
table.Type.Name,
TypeAttributes = TypeAttributes.Public,
CustomAttributes = {
- new CodeAttributeDeclaration("Table",
- new CodeAttributeArgument("Name", new
CodePrimitiveExpression(table.Name))),
+ new CodeAttributeDeclaration("Table", new
CodeAttributeArgument("Name",
+ new
CodePrimitiveExpression(table.Name.Split('.').Last()))),
},
};
@@ -734,24 +733,21 @@
var whenUpdating = new List<CodeStatement>(
from assoc in relatedAssociations
select (CodeStatement) new
CodeConditionStatement(
- new CodePropertyReferenceExpression(
- new
CodeVariableReferenceExpression(GetStorageFieldName(assoc)),
- "HasLoadedOrAssignedValue"),
- new CodeThrowExceptionStatement(
- new
CodeObjectCreateExpression(typeof(System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException)))));
- whenUpdating.Add(
- new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, onChanging, new
CodePropertySetValueReferenceExpression())));
+ new CodePropertyReferenceExpression(new
CodeVariableReferenceExpression(GetStorageFieldName(assoc)),
"HasLoadedOrAssignedValue"),
+ new CodeThrowExceptionStatement(new
CodeObjectCreateExpression(typeof(System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException)))));
+
+ whenUpdating.Add(new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, onChanging, new
CodePropertySetValueReferenceExpression())));
+
if (havePrimaryKeys)
- whenUpdating.Add(
- new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, "SendPropertyChanging")));
- whenUpdating.Add(
- new CodeAssignStatement(fieldReference, new
CodePropertySetValueReferenceExpression()));
+ whenUpdating.Add(new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, "SendPropertyChanging")));
+
+ whenUpdating.Add(new
CodeAssignStatement(fieldReference, new
CodePropertySetValueReferenceExpression()));
+
if (havePrimaryKeys)
- whenUpdating.Add(
- new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, "SendPropertyChanged", new
CodePrimitiveExpression(property.Name))));
- whenUpdating.Add(
- new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, onChanged)));
+ whenUpdating.Add(new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, "SendPropertyChanged", new
CodePrimitiveExpression(property.Name))));
+ whenUpdating.Add(new CodeExpressionStatement(new
CodeMethodInvokeExpression(thisReference, onChanged)));
+
var fieldType = TypeLoader.Load(column.Type);
// This is needed for
VB.NET generation;
// int/string/etc. can use '<>' for comparison, but
NOT arrays and other reference types.
@@ -760,9 +756,18 @@
// Thus, we need to special-case: if fieldType is a
ref or nullable type,
// generate '(field Is value) = false'; otherwise,
// generate '(field <> value)'
- CodeBinaryOperatorExpression condition =
fieldType.IsClass || fieldType.IsNullable()
- ? ValuesAreNotEqual_Ref(new
CodeVariableReferenceExpression(field.Name), new
CodePropertySetValueReferenceExpression())
- : ValuesAreNotEqual(new
CodeVariableReferenceExpression(field.Name), new
CodePropertySetValueReferenceExpression());
+ CodeExpression condition = null;
+ if (fieldType.IsClass || fieldType.IsNullable())
+ condition = ValuesAreNotEqual_Ref(new
CodeVariableReferenceExpression(field.Name),
+ new
CodePropertySetValueReferenceExpression());
+
+ else if(Provider.FileExtension.Equals("vb") &&
fieldType.IsValueType && column.CanBeNull)
+ condition = new
CodeSnippetExpression(String.Format("Not Nullable.Equals({0}, value)",
field.Name));
+
+ else
+ condition = ValuesAreNotEqual(new
CodeVariableReferenceExpression(field.Name),
+ new
CodePropertySetValueReferenceExpression());
+
property.SetStatements.Add(new
CodeConditionStatement(condition, whenUpdating.ToArray()));
_class.Members.Add(property);
}