Silverlight Authors: Automic Blog, Michael Kopp, AppDynamics Blog, Kaazing Blog, Steven Mandel

Related Topics: Silverlight, Microsoft Cloud, Machine Learning

Silverlight: Blog Feed Post

Silverlight 3 RTM and .NET RIA Services wirth NHibernate

I think NHibernate is an excellent example of the vibrant open source community on .NET that I’d like to support

   1: static ISessionFactory SessionFactory = CreateSessionFactory();
   2: static ISessionFactory CreateSessionFactory()
   3: {
   4:     return Fluently.Configure()
   5:       .Database(
   6:         MsSqlConfiguration.MsSql2005
   7:         .ConnectionString(c => c
   8:             .Is(ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString)
   9:             )
  10:       )
  11:       .Mappings(m =>
  12:        m.FluentMappings.AddFromAssemblyOf<SuperEmployeeDomainService>())
  13:        .BuildSessionFactory();
  15: }

Next, let’s look at the mapping class.. this shows how the data from the database are mapped into a .NET Class. 

   1: public class SuperEmployeesMap : ClassMap<SuperEmployee>
   2: {
   3:     public SuperEmployeesMap()
   4:     {
   5:         WithTable("SuperEmployees");
   6:         Id(x => x.EmployeeID);
   7:         Map(x => x.Name);
   8:         Map(x => x.Gender);
   9:         Map(x => x.Issues);
  10:         Map(x => x.LastEdit);
  11:         Map(x => x.Origin);
  12:         Map(x => x.Publishers);
  13:         Map(x => x.Sites);
  14:     }
  15: }

And here is the type I map the data into.  Notice this has the validation attributes for RIA Services to do the validation on the client and server. 

   1: public class SuperEmployee
   2: {
   3:         [Key]
   4:         [ReadOnly(true)]
   5:         public virtual int EmployeeID {get; set;}
   7:         [RegularExpression("^(?:m|M|male|Male|f|F|female|Female)$", 
   8:             ErrorMessage = "Gender must be 'Male' or 'Female'")]
   9:         public virtual string Gender { get; set; }
  11:         [Range(0, 10000,
  12:             ErrorMessage = "Issues must be between 0 and 1000")]
  13:         public virtual Nullable<int> Issues { get; set; }
  15:         public virtual Nullable<DateTime> LastEdit { get; set; }
  17:         [Required]
  18:         [StringLength(100)]
  19:         public virtual string Name { get; set; }
  21:         public virtual string Origin { get; set; }
  23:         public virtual string Publishers { get; set; }
  25:         public virtual string Sites { get; set; }
  26:     }


That’s the bulk of the NHibernate specific code.    Now let’s look at the DomainService..

   1: [EnableClientAccess()]
   2: public class SuperEmployeeDomainService : NHibernateDomainService
   3: {
   4:     public SuperEmployeeDomainService() :
   5:         base(SessionFactory) { }

First, in line 2, notice I have factored some of the plumbing code into a base class.  This is very simple (not production ready) example.. we will look it in more detail later. Then we return the static SessionFactory the the base class.  The SessionFactory is static such that it is created only once per AppDomain rather than on each request.

   1: public IQueryable<SuperEmployee> GetSuperEmployees()
   2: {
   3:     return Session.Linq<SuperEmployee>()
   4:             .Where(e => e.Issues > 10);
   5: }

Here we use NHibernate Linq to return an IQueryable that RIA Services can use to do paging, filtering, etc. 

Then we have Insert and Update which are very basic..

   1: public void InsertSuperEmployee(SuperEmployee superEmployee)
   2: {
   3:     Session.Save(superEmployee);
   4: }
   6: public void UpdateSuperEmployee(SuperEmployee currentSuperEmployee)
   7: {
   8:    Session.Update(currentSuperEmployee);
   9: }

Now, let’s take a look at the NHibernateDomainService base class… Again this is very basic, just to show the concepts..

   1: public class NHibernateDomainService : DomainService
   2: {
   4:     protected ISession Session;
   6:     public NHibernateDomainService(ISessionFactory sessionFactory)
   7:     {
   8:         this.Session = sessionFactory.OpenSession();
   9:     }
  12:     protected override void Dispose(bool disposing)
  13:     {
  14:         Session.Dispose();
  15:         base.Dispose(disposing);
  17:     }
  18:     protected override void ExecuteChangeSet(ChangeSet changeSet)
  19:     {
  20:         using (var trans = Session.BeginTransaction())
  21:         {
  22:             base.ExecuteChangeSet(changeSet);
  23:             trans.Commit();
  24:         }
  25:     }

Notice in the constructor we create the Session… then we close the session in the Dispose() method. 

The interesting bit is handling the ChangeSet… Notice we use a transaction to wrap the calls to our update\create methods.  This ensures that if their is any failure we roll back the changes (this is the contract for DomainService)…

Now, because we plug into the DomainService pattern, we get our silverlight client with paging, filtering, etc


…and validated editing.



But we also get ASP.NET support via the DomainDataSource as in this example from the sitemap.aspx

   1: <asp:DomainDataSource runat="server" ID="SitemapDataSource" 
   2:     DomainServiceTypeName="MyApp.Web.SuperEmployeeDomainService" 
   3:     SelectMethod="GetSuperEmployees" />


And we get a REST based interface via the Astoria support for DomainService.



And we get ASP.NET Dynamic Data Support, again with paging, filtering,


and validating editing.


And all the other presentation tiers..


Wow, pretty cool..

For more on NHibernate, check out Ayende’s blog

For more NHibernate and DomainService, check out Chris van de Steeg’s blog post ASP.NET MVC, DynamicData, Domain-/RiaServices, Unity and NHibernate: Part 1

Read the original blog entry...

More Stories By Brad Abrams

Brad Abrams is currently the Group Program Manager for the UI Framework and Services team at Microsoft which is responsible for delivering the developer platform that spans both client and web based applications, as well as the common services that are available to all applications. Specific technologies owned by this team include ASP.NET, Atlas and Windows Forms. He was a founding member of both the Common Language Runtime, and .NET Framework teams.

Brad has been designing parts of the .NET Framework since 1998 when he started his framework design career building the BCL (Base Class Library) that ships as a core part of the .NET Framework. He was also the lead editor on the Common Language Specification (CLS), the .NET Framework Design Guidelines, the libraries in the ECMA\ISO CLI Standard, and has been deeply involved with the WinFX and Windows Vista efforts from their beginning.

He co-authored Programming in the .NET Environment, and was editor on .NET Framework Standard Library Annotated Reference Vol 1 and Vol 2 and the Framework Design Guidelines.

@ThingsExpo Stories
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smart...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use of real time applications accelerate, legacy networks are no longer able to architecturally support cloud adoption and deliver the performance and security required by highly distributed enterprises. These outdated solutions have become more costly and complicated to implement, install, manage, and maintain.SD-WAN offers unlimited capabilities for accessing the benefits of the cloud and Internet. ...
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.