Skip to content

Commit

Permalink
Handled the m:null="true" attribute on a property.
Browse files Browse the repository at this point in the history
  • Loading branch information
visoft committed Aug 28, 2010
1 parent 48b5367 commit a8c4b27
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions features/type_conversion.feature
Expand Up @@ -43,3 +43,11 @@ Scenario: Verify that DateTimes don't change if not modified on an update
And I run the query
Then the new query result's time "AuditFields.CreateDate" should equal the saved query result

Scenario: DateTimes should be able to be null
Given I call "AddToProducts" on the service with a new "Product" object
And I save changes
When I call "Products" on the service
And I run the query
Then the "DiscontinuedDate" method should return a NilClass


4 changes: 4 additions & 0 deletions lib/ruby_odata/service.rb
Expand Up @@ -316,10 +316,14 @@ def complex_type_to_class(complex_type_xml)
# Field Converters
def parse_value(property_xml)
property_type = property_xml.attr('type')
property_null = property_xml.attr('null')

# Handle a nil property type, this is a string
return property_xml.content if property_type.nil?

# Handle anything marked as null
return nil if !property_null.nil? && property_null == "true"

# Handle complex types
return complex_type_to_class(property_xml) if !property_type.match(/^Edm/)

Expand Down
24 changes: 24 additions & 0 deletions test/SampleService/App_Code/Model.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/SampleService/App_Code/Model.edmx
Expand Up @@ -32,6 +32,7 @@
<Property Name="CreateDate" Type="datetime" Nullable="false" />
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
<Property Name="CreatedBy" Type="nvarchar" MaxLength="50" />
<Property Name="DiscontinuedDate" Type="datetime" />
</EntityType>
<Association Name="FK_CategoryProduct">
<End Role="Categories" Type="Model.Store.Categories" Multiplicity="1" />
Expand Down Expand Up @@ -67,6 +68,7 @@
<Property Type="Decimal" Name="Price" Nullable="false" />
<NavigationProperty Name="Category" Relationship="Model.CategoryProduct" FromRole="Product" ToRole="Category" />
<Property Name="AuditFields" Type="Model.AuditFields" Nullable="false" />
<Property Type="DateTime" Name="DiscontinuedDate" Nullable="true" />
</EntityType>
<EntityType Name="Category">
<Key>
Expand Down Expand Up @@ -94,6 +96,7 @@
<EntitySetMapping Name="Products">
<EntityTypeMapping TypeName="IsTypeOf(Model.Product)">
<MappingFragment StoreEntitySet="Products">
<ScalarProperty Name="DiscontinuedDate" ColumnName="DiscontinuedDate" />
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<ScalarProperty Name="Description" ColumnName="Description" />
Expand Down
Binary file modified test/SampleService/App_Data/_TestDB.mdf
Binary file not shown.
Binary file modified test/SampleService/App_Data/_TestDB_Log.ldf
Binary file not shown.

0 comments on commit a8c4b27

Please sign in to comment.