The Displaced Guy

Your personal IT guy
Subscribe

WCF RIA Services – Manually Adding a View to existing Entity Framework

September 03, 2010 By: DisplacedGuy Category: Microsoft SQL Server 2008, Programming, Silverlight 4, Visual Studio 2010, WCF RIA Services, Web Design

WCF RIA Services – Manually Adding a View to existing Entity Framework

When the real-world automatic stuff doesn’t work… you can add entities manually

Complex Views – Appear to get skipped upon “Update Schema from Database”

I’ve got one database view that is more complex than the visual editor seems to be capable of handling.  The “View” painter in Visual Studio chokes on it and I am pretty sure this is why EntityFramework doesn’t know what to do with it.

I wanted to include the view in my Silverlight 4, WCF RIA Services application but no matter what I tried, I couldn’t get the view to go into the Entity Framework Model.  Here is the definition for my SQL Server 2008 database view… if anyone knows how I could write this in a better way or one that Visual Studio likes please let me know.

with AllCategories
as (
	(select
		p.category_id,
		p.parent_id,
		p.description as parent_desc,
		p.description,
		0 as [level],
		p.url,
		p.sort_order,
		'N' as virtual_category
	from ld_category p
	where p.parent_id = 0)
		union all
	(select
		p.category_id,
		p.parent_id,
		(select c5.description from ld_category as c5 where c5.category_id = p.parent_id) as parent_desc,
		p.description,
		[level] + 1 ,
		p.url,
		p.sort_order,
		'N' as virtual_category
	from	ld_category p
			inner join AllCategories as c on p.parent_id = c.category_id and c.virtual_category = 'N')
		union all
    (SELECT
		q.category_id,
		q.parent_id,
		(select c6.description from ld_category as c6 where c6.category_id = q.parent_id) as parent_desc,
		(select c4.description from ld_category c4 where c4.category_id = q.category_id) as description,
		[level] + 1,
		(select c4.url from ld_category c4 where c4.category_id = q.category_id) as url,
		q.sort_order,
		'Y' as virtual_category
     FROM ld_category_clone AS q
		  inner join AllCategories as c ON q.parent_id = c.category_id and c.virtual_category = 'N'))
select  c.category_id, c.parent_id, c.parent_desc, c.description, level, c.sort_order, c.url,  c.virtual_category
from AllCategories c

Adding my Database View to Entity Framework Manually

Right click the Entity Framework Class and open with an XML editor.

Notice the three sections ( StorageModels, ConceptualModels, and Conceptual to Storage Mapping )  You need to add code to all three sections.

Entity Framework WCF RIA Sections

Entity Framework (Storage, Conceptual & Mapping)

First add your new entity to the StorageModels section.

<EntitySet Name="v_category" EntityType="linkdirectoryModel.Store.v_category" store:Type="Tables" Schema="dbo" />
<EntityType Name="v_category">
  <Key>
   <PropertyRef Name="category_id" />
   <PropertyRef Name="parent_id" />
  </Key>
  <Property Name="category_id" Type="int" Nullable="false"/>
  <Property Name="parent_id" Type="int" Nullable="false"/>
  <Property Name="parent_desc" Type="nvarchar" MaxLength="100" />
  <Property Name="description" Type="nvarchar" MaxLength="100" />
  <Property Name="level" Type="int" />
  <Property Name="sort_order" Type="int" />
  <Property Name="url" Type="nvarchar" MaxLength="200" />
  <Property Name="virtual_category" Type="varchar" MaxLength="1" />
</EntityType>

Second Add to the ConceptualModels section

note: my pluralization is consistent with others but in bad English form. ;)

<EntitySet Name="v_categorys" EntityType="linkdirectoryModel.v_category" />
<EntityType Name="v_category">
  <Key>
   <PropertyRef Name="category_id" />
   <PropertyRef Name="parent_id" />
  </Key>
  <Property Name="category_id" Type="Int32" Nullable="false" />
  <Property Name="parent_id" Type="Int32" Nullable="false"  />
  <Property Name="parent_desc" Type="String" MaxLength="100" />
  <Property Name="description" Type="String" MaxLength="100" />
  <Property Name="level" Type="Int32" />
  <Property Name="sort_order" Type="Int32" />
  <Property Name="url" Type="String" MaxLength="200" />
  <Property Name="virtual_category" Type="String" MaxLength="1" />
</EntityType>

Last Add Mappings to Runtime Mappings Section

<EntitySetMapping Name="v_categorys">
<EntityTypeMapping TypeName="linkdirectoryModel.v_category">
<MappingFragment StoreEntitySet="v_category">
	<ScalarProperty Name="category_id" ColumnName="category_id" />
	<ScalarProperty Name="parent_id" ColumnName="parent_id" />
	<ScalarProperty Name="parent_desc" ColumnName="parent_desc" />
	<ScalarProperty Name="description" ColumnName="description" />
	<ScalarProperty Name="level" ColumnName="level" />
	<ScalarProperty Name="sort_order" ColumnName="sort_order" />
	<ScalarProperty Name="url" ColumnName="url" />
	<ScalarProperty Name="virtual_category" ColumnName="virtual_category" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>

You need to make sure all errors are resolved before you can open again in “visual” mode.

Sincerely,
Rich (aka DisplacedGuy)

PowerBuilder – Any real competition? Exploring WCF RIA & Silverlight 4

September 01, 2010 By: DisplacedGuy Category: Microsoft SQL Server 2008, PowerBuilder, PowerBuilder Conversions, Programming, Silverlight 4, Visual Studio 2010, WCF RIA Services, Web Design

Do any development technologies stack up to PowerBuilder?

The question was almost rhetorical… but look at what I’ve done here.

Converting PowerBuilder to C Sharp .NET, WCF RIA Services and Silverlight 4

I know it is hard for some people to watch the big guys win all the time, but Microsoft has been up to some good things lately. I’ve used Visual Basic in some prior corporate projects and also done some light web development using ASP.NET several years ago.  Neither impressed me at all, they weren’t in the same ballpark as PowerBuilder as far as corporate development goes anyway.

My background, to put things into perspective here…  I am a PowerBuilder expert, a career PB developer with almost 20 years experience starting with version 3.0.   I’ve been trying to find the next best thing to PowerBuilder.

I previously wrote about was WaveMaker which is a good option especially if you like Java or your company is a Java shop.  I regret to say this, but if you are a PB developer without Java experience you are going to find yourself more comfortable learning Microsoft.

The .NET Framework 4 has evolved to become a viable competitor in the market.

Overview of Windows Communication Foundation in .NET Framework 4

PowerBuilder to WCF Conversions

WCF handles interoperability and security

WCF was created to support the move towards service-oriented software development.   In a nutshell WCF handles challenges of interoperability and security between systems of different platforms, such as Java EE and .NET that may require different security or transaction handling across local networks or the internet.

This graphic helps illustrate all of the technologies that would have been required in the prior version of .NET and were reasons that I lost interest in learning some of the prior versions of .NET.

The Microsoft site has a very detailed introduction to WCF in .Net Framework 4, and is where I borrowed above graphic from.

Overview of WCF RIA Services

WCF RIA Services is brand new this year and provides the ability to write application logic that runs on the middle tier and controls access to pre-defined queries or business logic.  WCF RIA is specific to Silverlight 4 and simplifies the authentication and data validation on the Silverlight platform.

Visual Studio 2010 generates the RIA Services from your Entity Model and allows you to customize the generated services or add extra business logic.  Unlike some tools that generate objects from your schema, Visual Studio is one of the best at handling data model changes after the fact.  This is a huge plus because let’s face it, there is almost always something overlooked before development starts.

Overview of Silverlight 4

Silverlight 4 is the platform for creating visually appealing and media rich user interfaces.  As a PowerBuilder developer you are going to have fun with Silverlight 4.  Visual Studio 2010 is an amazing IDE and Silverlight has come a long way in version 4.  The old days of VB where you had to bind a grid directly to a database are gone thank goodness.  Don’t expect datawindow functionality but you can count on an impressive arsenal of controls that almost make up for the lack of datawindow.  Another big plus and advantage over PowerBuilder is the quality and quantity of help files, sample programs and instructional videos.  The intelli-sense alone in VS2010 is enough get any object oriented PB developer up to speed very quickly.

Converting PowerBuilder Applications

So how does this technology stack up to PowerBuilder as a whole?  Not bad!  An experienced PB developer should be able to pick up these technologies and become somewhat productive in a couple weeks maybe a little longer if you are not familiar with WPF or XAML.

The Datawindow – How to manage without it

The DataGrid and Grid in Silverlight 4 allow you to bind to various data sources, has tons of flexibility and adequate events for meeting most business requirements.  Silverlight with RIA Services can even handle detecting changes made to the data and updating the database as long as your data model was well defined and all the associations made in your Entity Data Model.  I’ve found that in real-world applications much of the automatic “Marketing Magic” stuff never applies and in my application I ended up doing retrieval and update manually.

PowerBuilder Datwindow Buffers and Detecting Changes In Data

The .NET Framework has a class called ObservableCollections which inherits from Lists which inherits from Arrays (don’t quote me on this…) but the concept can be used in a remotely similar way as datawindow buffers in that they “observe changes” in the underlying rows or columns and you can perform actions based on the changes.

PowerBuilder Dataobjects – Free Form & Grid Style

Silverlight uses a basic Grid for “Free Form” style dataobjects consisting of many separate controls.

Silverlight has a DataGrid object which would be used for “Grid” style dataobjects.  It is nothing more than an XAML wrapper with one to many DataTemplate objects for each column each of them having a special “Header”  property defining the header.  Listed below is a possible mapping of these control types to PowerBuilder dataobject column edit styles.

Possible PowerBuilder to Silverlight 4 Mappings

PowerBuilderSilverlight 4 Data Template
SingleLineEditTextBox
EditMask (Date)sdk:DatePicker
EditMask (String Format)TextBlock
Labelsdk:Label
DropDownDataWindowComboBox
DropDownListBoxComboBox
PictureImage
CheckBoxCheckBox
RadioButtonRadioButton
Tab/TabControlTabControl
OvalEllipse
RectangleRectangle
SingleLineEdit (with code)AutoCompleteBox
RichTextEditRichTextBox
Datawindow (Free Form)Grid (with many controls)
Datawindow (Grid, Tabular)DataGrid (with many controls)

Other Comments about the transition from PowerBuilder to .NET, WCF RIA & Silverlight 4

Overall the process of converting a PowerBuilder application went very well.  Every technical challenge was easily overcome by reading the vast amount of documentation, or finding the same thing on a developer blog.   I believe most PB developers will enjoy Silverlight 4, and eventually like it even more than PowerBuilder.  I didn’t go into the advanced possibilities with Silverlight 4, but you can do some pretty amazing things and customize just about any control, one example is a TreeView, with Templates you can define how the tree expands and display multiple columns in multiple formats for each treeviewitem.

I believe this combination is a viable PB alternative and one that most PB developers would enjoy.  If you have to choose one area to start learning in, Silverlight 4 is the most fun and the Silverlight website has tons of good information about learning and sample websites that will get you excited to start learning.  My program below doesn’t look too shabby for a weeks worth of development most of which was learning.

Here is a snapshot of my converted application, it is the Admin component to a publicly accessible link directory.  The database is Microsoft SQL Server 2008. The actual public part of the link directory this data represents is at My Orlando Information Link Directory

This program below was redeveloped in Visual Studio 2010 C#.NET with WCF RIA Services as mid-tier accessing a Microsoft  SQL Server 2008 and Silverlight 4 for the User Interface.   The Free form data grid still has a small amount of work tying the drop down value.

PowerBuilder to WCF RIA and Silverlight 4

PowerBuilder to WCF RIA and Silverlight 4

Sincerely

Rich (aka DisplacedGuy)


DisplacedGuy – Adsense Stats & Ugly Secrets of Making Money Online Series Part 3

August 16, 2010 By: DisplacedGuy Category: Adsense, Adwords, Analytics, Blogging for Cash, Generate Traffic, Make Money Online Series, Making Money, Part III - Stats, Programming, WordPress

DisplacedGuy.Com – Actual Google Adsense website statistics and ugly secrets of making money online series – Part 3.

Google Adsense – Actual Blogging Statistics

April, 2010 v.s. July, 2010 –  Stats –  What do they tell us?

Blogging for Money - PowerBuilder, WaveMaker, Adsense

DisplacedGuy.Com - First Month v.s. Current Month Stats

First of all, why am I sharing these?

I started this website back around the middle of March, 2010 and much about it was a learning experience to me.  I had very little experience with WordPress, running a blog, monetizing a blog, writing articles or analyzing stats with Google Analytics.  My initial intention was to share technical information, expand my network of friends, learn as much as possible, and make some money blogging.

I just finished an eight year PowerBuilder contract and was burned out, so used this opportunity to expand my horizons and try new things.   I was disappointed at the lack of information available about starting a blog, in particular information about making money online which I needed because my contract had just ended.  For example, was it possible to make money online, what things work and what things don’t work,  how long does it take?  You can find links to the first two parts to this series at the end of the article.

I’ll tell you everything for $4.99 plus shipping and handling!  Just kidding… please stick with me…

I always used to say that you could find the answer to anything on the web if you look hard enough, but in this case, it wasn’t true.  I found tons of answers but most of them were not believable because the writer demanded money in return for the “technique” or “secret” to making money online.   It was quite disappointing.  I figured that if I agreed up-front to share all my information that I could gain some readers who could appreciate someone with values and integrity and I needed all the help I could get because I knew that my writing was not going to win me any awards.

You know those web pages where you are reading, and they sound exciting, and they are filled with BOLD text, bright colors popping out at you with motivational words?  The farther you read into the article the more you realize you are being lured in…  if you make it to the end there is usually a huge button, or something warning you that you need to click it NOW, or the opportunity will vanish.  This is the point where they either get you… hook, line and sinker,  or you move on to another page never return.  This concept is called a “Squeeze Page”, and they are generally quite profitable.  The sleazier you make them the more profitable they usually are.   I’ve seen some pretty good squeeze pages with logos of companies that would cringe if they knew.  Many of the Squeeze pages go up and move.   I haven’t figured out how they funnel massive amounts of traffic to them.

Summary of DisplacedGuy.Com Experiences to date

I’ve learned a lot, and the entire process has been rewarding in many ways.  I’ve made new friends from all over the world, made new business contacts, have been introduced to new technologies,  learned the basics of blogging and monetizing websites and hopefully I’ve helped a few others with the same thing.   I’ve also learned writing quality articles is much more time consuming than I ever imagined and it takes a serious amount of discipline to keep writing at a steady pace.

Here is a link to my first post of DisplacedGuy.Com actual statistics

Fact #1 –  Web Traffic and Visitors is increasing at a significant rate.  This is good!

Blogging for Money - PowerBuilder, WaveMaker, Java, .NET, Silverlight

I remember the first months being very disappointed of the low traffic and very occasional number of comments.  Just a few short months later and I am to the point that I can’t keep up with comments quite honestly they are out of control and I’ve got a WordPress widget that helps identify and delete the obvious spam comments.  If you leave a comment on any site and it takes a long time to get approved, don’t feel bad the website owner is probably dealing with hundreds of spam comments per day.

My Tip #1 for improving Web Traffic – Be active in your community & share the love where it is deserved

I don’t advertise or spend any significant amount of time sharing my site.   Most of the traffic growth has come from my normal activities on technical sites such as dzone.com, asp.net, wavemaker.com.  For example, I’ve got accounts on those sites and I read articles, comment on them and post technical questions on forums and answer questions on forums.  Sounds easy, and it is.

You’ll read about posting your URL on tons of directory sites and raising the Google page rank, but honestly I haven’t done that and am happy with the traffic growth.  So skip that stuff, focus on adding fresh content (I was weak at this) and staying active in your technical community.  Find good articles and comment on them, let the author know if they did a good job and you’ll likely find that author on your site returning the favor.  It has to be real, sincerity is one of the most difficult things to fake so why bother trying.

If you are starting a technical blog and looking for traffic, the simple act of “being yourself” and networking will gain you a lot of traffic.  Make sure to list your site in your profile.  You don’t need to pimp your site, it’s better to be patient and let the traffic come naturally.

Fact #2 –  Traffic and Revenue do go hand-in-hand, but the ratio depends heavily on your blog category and type readers it will attract

Google Analytics - Make money online tips

DisplacedGuy.Com Adsense - Money Earned

Some of you may notice the format of this page is different than the actual on Google Analytics.  It’s because I reformatted it to take less space, but the data is actual.

The bottom line here is that monetization of DisplacedGuy.com is almost a complete failure.  I’ve followed tips learned such as making the advertisements blend in nicely, by not putting too many ads ( I reduced to one ad per article ) but the truth of the matter is that highly technical readers are the worst you can get as far as achieving a good click through rate.  I’ve said this before, if your primary intention is making money online then blog about something non-technical where your readers are not as adept at (or don’t care) identifying what is an advertisement and what is content.  I’ve monetized a few of my other sites and can prove this theory.

Is making money online is a simple numbers game?

With these numbers you should be able to determine how much traffic you need to generate any particular amount of money, but consider the principle of Occams Razor!

  1. How much do you earn per ad click?  ( AdSense Revenue /  AdSense Ads Clicked )
  2. How many adsense unit impressions need to be shown before someone clicks an ad? ( AdSense CTR)
  3. How many ads does an average visitor click?  This is just another way of wording #2   ( AdSense Ads Clicked / Visit )
  4. How much ad revenue does your site make per 1000 visits?  ( AdSense Revenue / 1000 visits )
DisplacedGuy.Com actuals for two month period Jun 14, 2010 to Aug 14, 2010:
  1. The average revenue earned per ad click is $0.25 (  $1.78  /  7   =   $0.25 )
  2. One ad is clicked for every 241 ad impressions made.  ( 1,685 / 7 = 241 )   — A Click through Rate of 0.67%  (Embarrassingly Low)
  3. Each visitor clicks .01 ads   ( 7 / 835 = .01 )  -  (Embarrassingly Low)
  4. This site makes about $2.14 per 1000 visits
  • Question: How many visits per day needed to earn $50K per year?
  • Answer: 66,376 visitors per day !
Making Money online Adsense

Making Money Online - Simple Numbers Game


Fact #3 –  Perceived quality decreased

Notice the bounce rate increased slightly, this would imply that readers are not sticking around to read multiple articles.  It’s generally a bad sign, and makes sense considering that I don’t keep up with lots of new content.

Also notice number of pages viewed per visitor is down, also one of the negative statistics.

Summary

I’ve shown you some of the basics of Adsense and Google Analytics.  We’ve learned that trying to make money online via a technical blog, or make money online themed blog is probably one of the most difficult and that focusing on niches that attract the less technical savvy reader offer you a much better chance.   I’ve given you an ugly hint that “Squeeze” pages are effective money making strategy, however they aren’t for everyone (including me).

As promised I shared my actual statistics and I’ll continue to do so.  I can only hope that the advertisement click through rates improve, but I won’t hold my breath but don’t expect a flurry of high quality articles either.  This site will continue to be my hobby, a source to meet new people, learn new things and help others.  I hope you enjoyed.  I love real comments, they are great reward for effort in creating articles.

See prior articles;  Part 1 and Part 2 of the Making Money Online Series

Sincerely,

Rich Bianco

(aka DisplacedGuy)

I need feedback…

As a side-job, I created a new version of a website for a friend.  She is a fashion designer and wanted a site that was easier to navigate, larger, didn’t have such hard edges, and did a better job showing the photo galleries.  Would you be so kind as to look at both versions, and offer any suggestions or feedback to me?  Also if you like the website and want one made, I can make you a site of similar complexity for a very reasonable cost.  Web design (in the art form) isn’t my area of expertise but I enjoy learning it, plus it will help me in the business site development area.

Old – Existing Site

http://www.lialiacollection.com/

New Proposed Site

http://www.lialiacollection.com/lialia_v2/


WP SlimStat