Datei: NDODLL/SqlPersistenceHandling/AssignmentGenerator.cs

Last Commit (123a4dc)
1 using NDO.Mapping;
2 using NDOInterfaces;
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Reflection;
7 using System.Text;
8
9 namespace NDO.SqlPersistenceHandling
10 {
11 ····internal class AssignmentGenerator
12 ····{
13 ········IProvider provider;
14 ········List<string> fields = new List<string>();
15
16 ········public AssignmentGenerator( Class cls )
17 ········{
18 ············this.provider = cls.Provider;
19 ············FieldMap fm = new FieldMap( cls );
20 ············foreach (var e in fm.PersistentFields)
21 ············{
22 Type memberType;
23 if ( e. Value is FieldInfo)
24 ····················memberType = ((FieldInfo)e.Value).FieldType;
25 ················else
26 ····················memberType = ((PropertyInfo)e.Value).PropertyType;
27
28 ················var fieldMapping = cls.FindField( (string)e.Key );
29 ················if (fieldMapping != null)
30 ················{
31 ····················fields.Add( fieldMapping.Column.Name );
32 ················}
33 ············}
34
35 ············var relationInfos = new RelationCollector( cls ).CollectRelations().ToList();
36
37 ············foreach (RelationFieldInfo ri in relationInfos)
38 ············{
39 ················Relation r = ri.Rel;
40 ················if (r.Multiplicity == RelationMultiplicity.Element && r.MappingTable == null
41 ····················|| r.Multiplicity == RelationMultiplicity.List && r.MappingTable == null && r.Parent.FullName != cls.FullName)
42 ················{
43 ····················foreach (ForeignKeyColumn fkColumn in r.ForeignKeyColumns)
44 ····················{
45 ························fields.Add( fkColumn.Name );
46 ························Type systemType = fkColumn.SystemType;
47 ····················}
48 ····················if (r.ForeignKeyTypeColumnName != null)
49 ····················{
50 ························fields.Add( r.ForeignKeyTypeColumnName );
51 ····················}
52 ················}
53 ············}
54 ············if (cls.TimeStampColumn != null)
55 ············{
56 ················fields.Add( cls.TimeStampColumn );
57 ············}
58
59 ········}
60
61 ········public string Result
62 ········{
63 ············get
64 ············{
65 ················StringBuilder result = new StringBuilder();
66 ················int ende = fields.Count - 1;
67 ················for (int i = 0; i < fields.Count; i++)
68 ················{
69 ····················string fieldName = (string)fields[i];
70 ····················result.Append( provider.GetQuotedName( fieldName ) );
71 ····················result.Append( " = " );
72 ····················if (!provider.UseNamedParams)
73 ························result.Append( "?" );
74 ····················else
75 ····················{
76 ························result.Append( provider.GetNamedParameter( "U_" + fieldName ) );
77 ····················}
78 ····················if (i < ende)
79 ····················{
80 ························result.Append( ", " );
81 ····················}
82 ················}
83 ················return result.ToString();
84 ············}
85 ········}
86 ····}
87 }
88
New Commit (16046d5)
1 using NDO.Mapping;
2 using NDOInterfaces;
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Reflection;
7 using System.Text;
8
9 namespace NDO.SqlPersistenceHandling
10 {
11 ····internal class AssignmentGenerator
12 ····{
13 ········IProvider provider;
14 ········List<string> fields = new List<string>();
15
16 ········public AssignmentGenerator( Class cls )
17 ········{
18 ············this.provider = cls.Provider;
19 ············FieldMap fm = new FieldMap( cls );
20 ············foreach (var e in fm.PersistentFields)
21 ············{
22 if ( e. Value. CustomAttributes. Any( c => c. AttributeType == typeof( NDOReadOnlyAttribute ) ) )
23 continue;
 
 
 
24
25 ················var fieldMapping = cls.FindField( (string)e.Key );
26 ················if (fieldMapping != null)
27 ················{
28 ····················fields.Add( fieldMapping.Column.Name );
29 ················}
30 ············}
31
32 ············var relationInfos = new RelationCollector( cls ).CollectRelations().ToList();
33
34 ············foreach (RelationFieldInfo ri in relationInfos)
35 ············{
36 ················Relation r = ri.Rel;
37 ················if (r.Multiplicity == RelationMultiplicity.Element && r.MappingTable == null
38 ····················|| r.Multiplicity == RelationMultiplicity.List && r.MappingTable == null && r.Parent.FullName != cls.FullName)
39 ················{
40 ····················foreach (ForeignKeyColumn fkColumn in r.ForeignKeyColumns)
41 ····················{
42 ························fields.Add( fkColumn.Name );
43 ························Type systemType = fkColumn.SystemType;
44 ····················}
45 ····················if (r.ForeignKeyTypeColumnName != null)
46 ····················{
47 ························fields.Add( r.ForeignKeyTypeColumnName );
48 ····················}
49 ················}
50 ············}
51 ············if (cls.TimeStampColumn != null)
52 ············{
53 ················fields.Add( cls.TimeStampColumn );
54 ············}
55
56 ········}
57
58 ········public string Result
59 ········{
60 ············get
61 ············{
62 ················StringBuilder result = new StringBuilder();
63 ················int ende = fields.Count - 1;
64 ················for (int i = 0; i < fields.Count; i++)
65 ················{
66 ····················string fieldName = (string)fields[i];
67 ····················result.Append( provider.GetQuotedName( fieldName ) );
68 ····················result.Append( " = " );
69 ····················if (!provider.UseNamedParams)
70 ························result.Append( "?" );
71 ····················else
72 ····················{
73 ························result.Append( provider.GetNamedParameter( "U_" + fieldName ) );
74 ····················}
75 ····················if (i < ende)
76 ····················{
77 ························result.Append( ", " );
78 ····················}
79 ················}
80 ················return result.ToString();
81 ············}
82 ········}
83 ····}
84 }
85