New Feature: Artificial Fields

Posted by: the telerik blogs, on 07 Jul 2009 | View original | Bookmarked: 0 time(s)

Artificial fields, what are they good for?

OpenAccess requires a persistent class model to work. This means that data not represented by a field in a persistent class cannot be stored or retrieved.Sometimes you need to add new data to your application during runtime. With many other ORMs you have to add a field to your persistent class, recompile everything and update the database schema.That is a little unhandy and looks like you always need a developer to do so.

OpenAccess Artificial Fields can help you to add such new data definitions on the fly. You can specify the field definition with the complete mapping in an xml format and OpenAccess can use it to add the new field to the internal class definition and to the database schema.

Here is an example of the XML mapping that adds an age field to the Person class definition.

<artificial> 
  <mapping id="artificialMapping1"> 
    <namespace name="AddressDataModel"> 
      <class name="Person"> 
        <field name="age" clr="System.Int32" /> 
      </class> 
    </namespace> 
  </mapping> 
</artificial> 

It is necessary that the class AddressDataModel already exists and is defined as persistent class. The code adds a field named age with type integer to the existing persistent class AddressDataModel. But what about the database schema?The trick is now that the OpenAccess generated schema can be updated by the schema API, it is possible because of the forward mapping capabilities of OpenAccess.

string ddlscript = database.GetSchemaHandler().CreateUpdateDDLScript(null); 
if (!string.IsNullOrEmpty(ddlscript)) 
    database.GetSchemaHandler().ExecuteDDLScript(ddlscript); 
 

The only open question now is; how can we access the new field? It is not showing up in the class itself because we did not change any code. The access has to be done via the OpenAccess generic access API described in this blog post.

A complete example can be found in the OpenAccess 2009 Q2 release. Start the QuickStartFramwork from the start menu and choose the GenericAccessAndArtificialFields example.


Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: XSD | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1046 | Hits: 91

Similar Posts

  • Introducing SharePoint 2010 Training at U2U more
  • New Entity Framework Feature CTP for VS2010 Beta 2 more
  • Examining ASP.NET 2.0's Membership, Roles, and Profile - Part 17 more
  • Telerik OpenAccess ORM introduces the industry-first full support for SQL Azure and extends functionality more
  • Visual Studio Extensions for RadControls for Silverlight Coming with Q3 2009 Release more
  • Using T4 Templates for Simple DTOs more
  • Choose your preferred data layout with RadListView for ASP.NET AJAX more
  • 500 Screencasts and Counting more
  • IIS Media Services 3.0 more
  • WebAii Testing Framework Support for Extended Silverlight RadControls more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD