Skip to content

Commit a014a86

Browse files
committed
Cleaned up warnings, moved known schemas into core project.
1 parent 9d40650 commit a014a86

7 files changed

Lines changed: 57 additions & 33 deletions

File tree

DataBoss.Specs/DataBossMappingSource.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Linq;
77
using System.Reflection;
88

9+
using LinqTableAttribute = System.Data.Linq.Mapping.TableAttribute;
10+
911
namespace DataBoss.Specs
1012
{
1113
class DataBossMappingSource : MappingSource
@@ -20,11 +22,11 @@ public DataBossTable(MetaModel model, Type rowType) {
2022
this.rowType = rowType;
2123
}
2224

23-
public override MetaModel Model { get { return model; } }
25+
public override MetaModel Model => model;
2426

2527
public override string TableName {
2628
get {
27-
var linqTable = rowType.GetCustomAttributes(typeof(System.Data.Linq.Mapping.TableAttribute), true).Cast<System.Data.Linq.Mapping.TableAttribute>().SingleOrDefault();
29+
var linqTable = rowType.GetCustomAttributes(typeof(LinqTableAttribute), true).Cast<LinqTableAttribute>().SingleOrDefault();
2830
if(linqTable != null)
2931
return linqTable.Name;
3032
var table = rowType.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute), true).Cast<System.ComponentModel.DataAnnotations.Schema.TableAttribute>().Single();
@@ -73,25 +75,25 @@ public DataBossRowType(MetaTable table, Type type) {
7375
}
7476
}
7577

76-
public override MetaTable Table { get { return table; } }
78+
public override MetaTable Table => table;
7779

78-
public override Type Type { get { return type; } }
80+
public override Type Type => type;
7981

80-
public override ReadOnlyCollection<MetaAssociation> Associations { get { return NoAssociations; } }
82+
public override ReadOnlyCollection<MetaAssociation> Associations => NoAssociations;
8183

82-
public override ReadOnlyCollection<MetaDataMember> PersistentDataMembers { get { return members.AsReadOnly(); } }
84+
public override ReadOnlyCollection<MetaDataMember> PersistentDataMembers => members.AsReadOnly();
8385

84-
public override MetaType InheritanceRoot { get { return null; } }
86+
public override MetaType InheritanceRoot => null;
8587

8688
public override MetaType GetInheritanceType(Type type) {
8789
if(type == this.type)
8890
return this;
8991
throw new NotSupportedException("Can't locate inheritance type for " + type.FullName);
9092
}
9193

92-
public override bool IsEntity { get { return false; } }
94+
public override bool IsEntity => false;
9395

94-
public override ReadOnlyCollection<MetaDataMember> IdentityMembers { get { return NoMembers; } }
96+
public override ReadOnlyCollection<MetaDataMember> IdentityMembers => NoMembers;
9597

9698
public override bool CanInstantiate {
9799
get { throw new NotImplementedException(); }
@@ -132,7 +134,7 @@ public override bool HasAnyValidateMethod {
132134
get { throw new NotImplementedException(); }
133135
}
134136

135-
public override bool HasInheritance { get { return false; } }
137+
public override bool HasInheritance => false;
136138

137139
public override bool HasInheritanceCode {
138140
get { throw new NotImplementedException(); }
@@ -197,19 +199,19 @@ public DataBossDataMember(MetaType declaringType, MemberInfo member, Type member
197199
this.name = name;
198200
}
199201

200-
public override string MappedName { get { return name; } }
202+
public override string MappedName => name;
201203

202-
public override MemberInfo Member { get { return member; } }
204+
public override MemberInfo Member => member;
203205

204-
public override bool IsAssociation { get { return false; } }
206+
public override bool IsAssociation => false;
205207

206-
public override bool IsDeferred { get { return false; } }
208+
public override bool IsDeferred => false;
207209

208-
public override Type Type { get { return memberType; } }
210+
public override Type Type => memberType;
209211

210-
public override string DbType { get { return DataBossScripter.ToDbType(memberType, member); } }
212+
public override string DbType => DataBossScripter.ToDbType(memberType, member);
211213

212-
public override MetaType DeclaringType { get { return declaringType; } }
214+
public override MetaType DeclaringType => declaringType;
213215

214216
public override MetaAssociation Association {
215217
get { throw new NotImplementedException(); }
@@ -297,9 +299,9 @@ public DataBossMetaModel(Type contextType) {
297299
this.contextType = contextType;
298300
}
299301

300-
public override Type ContextType { get { return contextType; } }
302+
public override Type ContextType => contextType;
301303

302-
public override Type ProviderType { get { return typeof(Sql2005Provider); } }
304+
public override Type ProviderType => typeof(Sql2005Provider);
303305

304306
public override MetaTable GetTable(Type rowType) {
305307
MetaTable cached;

DataBoss.Specs/DataBossMigratorSpec.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ public void Begin(DataBossMigrationInfo info) {}
2222

2323
public bool Execute(string query) {
2424
var result = true;
25-
if(OnExecute != null)
26-
result = OnExecute(query);
25+
if(OnExecute != null) {
26+
try {
27+
result = OnExecute(query);
28+
} catch(Exception e) {
29+
result = false;
30+
OnError?.Invoke(this, new ErrorEventArgs(e));
31+
}
32+
}
2733
ExecutedQueries.Add(query);
2834
return result;
2935
}

DataBoss.Specs/DataBossSpec.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@
55
using System.Data.Linq.Mapping;
66
using System.Data.SqlClient;
77
using System.Linq;
8+
using DataBoss.SqlServer;
89

910
namespace DataBoss.Specs
1011
{
11-
[Table(Name = "sys.objects")]
12-
class SysObjects
13-
{
14-
[Column(Name = "name")]
15-
public string Name;
16-
}
17-
1812
[Feature("DataBoss")]
1913
public class DataBossSpec
2014
{

DataBoss.Specs/ObjectReaderSpec.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,16 @@ public void converter_fills_public_fields() {
127127
}
128128

129129
class ValueRow<T> { public T Value; }
130+
130131
public void supports_float_field() {
131132
var source = new SimpleDataReader("Value");
132-
source.Add(3.14f);
133+
var expected = new ValueRow<float> { Value = 3.14f };
134+
source.Add(expected.Value);
133135
var reader = new ObjectReader();
134-
Check.That(() => reader.Read<ValueRow<float>>(source).Count() == source.Count);
136+
var rows = (ValueRow<float>[])Check.That(() => reader.Read<ValueRow<float>>(source).ToArray() != null);
137+
Check.That(
138+
() => rows.Length == 1,
139+
() => rows[0].Value == expected.Value);
135140
}
136141

137142
public void can_read_nullable_field() {

DataBoss/DataBoss.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Compile Include="Properties\Version.cs" />
6969
<Compile Include="Schema\ClusteredAttribute.cs" />
7070
<Compile Include="Schema\DataBossHistory.cs" />
71+
<Compile Include="SqlServer\SysObjects.cs" />
7172
</ItemGroup>
7273
<ItemGroup>
7374
<EmbeddedResource Include="Usage.txt">

DataBoss/DataBossScriptMigrationScope.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ public void Begin(DataBossMigrationInfo info) {
2525
}
2626

2727
public bool Execute(string query) {
28-
output.WriteLine(query);
29-
output.WriteLine(BatchSeparator);
30-
return true;
28+
try {
29+
output.WriteLine(query);
30+
output.WriteLine(BatchSeparator);
31+
return true;
32+
} catch(Exception e) {
33+
OnError?.Invoke(this, new ErrorEventArgs(e));
34+
return false;
35+
}
3136
}
3237

3338
public void Done() {

DataBoss/SqlServer/SysObjects.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace DataBoss.SqlServer
4+
{
5+
[Table("sys.objects")]
6+
public class SysObjects
7+
{
8+
[Column("name")]
9+
public string Name;
10+
}
11+
}

0 commit comments

Comments
 (0)