1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
.Generator
.Components
18 using System
.Collections
;
20 using Castle
.ActiveRecord
.Generator
.Components
.Database
;
23 public class PlainFieldInferenceService
: IPlainFieldInferenceService
25 private INamingService _namingService
;
26 private ITypeInferenceService _typeInfService
;
28 public PlainFieldInferenceService(INamingService namingService
, ITypeInferenceService typeInfService
)
30 _namingService
= namingService
;
31 _typeInfService
= typeInfService
;
34 #region IPlainFieldInferenceService Members
36 public ActiveRecordPropertyDescriptor
[] InferProperties(TableDefinition tableDef
)
38 ArrayList list
= new ArrayList();
40 foreach(ColumnDefinition col
in tableDef
.Columns
)
42 if (col
.ForeignKey
) continue;
44 String propertyName
= _namingService
.CreatePropertyName(col
.Name
);
45 Type propertyType
= _typeInfService
.ConvertOleType(col
.Type
);
46 String colType
= col
.Type
.ToString();
47 String colName
= col
.Name
;
49 ActiveRecordFieldDescriptor field
= null;
53 field
= new ActiveRecordPrimaryKeyDescriptor(
54 colName
, colType
, propertyName
, propertyType
, "Native");
58 field
= new ActiveRecordFieldDescriptor(
59 colName
, colType
, propertyName
, propertyType
, col
.Nullable
);
65 return (ActiveRecordFieldDescriptor
[]) list
.ToArray( typeof(ActiveRecordFieldDescriptor
) );