Wednesday, April 18, 2012

Update WCF RIA services Domain service when entity model has changed

Problem

When you need to add an extra table from the database in the entity model, you need it to be reflected in the RIA services. This does not happen automatically.

Solution

I had more or less guessed that generating another domain service would help create the code that could then be pasted in the original domain service. I found the confirmation in David Yack's blog article

Add a new table to a RIA services model and Domain service

The example a WCF RIA services library project in a LightSwitch solution.

The model AdventureWorksModel.edmx is based on 4 tables of the AdventureWorks database (Product, ProductModel, ProductCategory, ProductSubCategory).

The DomainService class has been created on the basis of this model and is called AdventurWorksDomainService.cs.

The underlying database is the AdventureWorks database. My RIA services project already contains 4 tables and now I want to add a 5th table BillOfMaterials, by rightclicking on the design surface of the model, choosing ‘Updating Model from the Database’, after selection of the 5th table, it was added to the model.

image

Now first save and build the project.

Now I add a new DomainService class to the project, called DomainServiceTemp, click Add.

image

From the entities, select only the BillOfMaterials, with enable Editing, Uncheck ‘enable client access. click OK.

image

Once the class and accompanying metadata class are generated:

  • copy the code from the BillOfmaterials class in the DomainServiceTemp.cs to the AdventureWorksDomainService.cs class
  • copy the code for the BillOfmaterials from the metadata temp file to the AdventureWorks metadata.
  • Delete the 2 temporary domainservice files.

Set attribute [Query(IsDefault = true)]

Before we can use the BillOfMeterials in the LightSwitch project, one of the Queries in the DomainServiceClass has to be declared as default query, otherwise LS will not accept it. I had before by me for the 4 other tables, now one line has to be added before the GetBillOfMaterials() Iqueryable method.

[Query(IsDefault = true)]
public IQueryable<BillOfMaterials> GetBillOfMaterials()

To use the new table in LS we build the WCF RIA Service project.


Remark


when a new column is added to the table, the only thing you need to do is copy the columns from the metadata file.


Update the data source in the LightSwitch project


Once the WCF RIA services project is rebuilt, we can update the data source in the LightSwitch project. The LS project already uses 4 of the 5 tables, now I can add the 5th. In the Select Data Source Objects the 5th table has just been selected.


image


The entity is add to the LS project


image


Conclusion


Once you start using WCF RIA services it is always wise to plan well ahead so that all necessary tables , views, stored procedures are included in the DomainService. But in a real world there are many different causes why some table data has to be added or updated afterwards. It can be added with a little manual intervention from the developer.

22 comments:

Anonymous said...

I like the valuable information you provide in your articles.
I will bookmark your blog and check again here regularly.
I'm quite certain I will learn many new stuff right here! Best of luck for the next!

Have a look at my blog: golf course gps devices *heraudition.com*

Anonymous said...

Right here is the right website for anybody who hopes to understand this topic.
You realize a whole lot its almost tough to argue with
you (not that I actually will need to…HaHa). You certainly
put a fresh spin on a subject that's been written about for ages. Excellent stuff, just excellent!

Also visit my site garmin watch for golf - www.rejestic.com -

Anonymous said...

Very good information. Lucky me I recently found your site by accident (stumbleupon).

I have saved as a favorite for later!

Also visit my site ... best gps for hiking ()

Anonymous said...

Very useful and informative blog.when a new column is added to the table, the only thing you need to do is copy the columns from the metadata file.Very good remark!!!

Ria Databases

Anonymous said...

Wow, amazing blog layout! How long have you been blogging for?
you make blogging look easy. The total glance of your site is great, let
alone the content material!

Look ino mmy web-site buy levitra online

Anonymous said...

Sono davvero impressionato con le vostre abilità di scrittura ,
così come con il layout sul tuo blog . È questo un tema
pagato o hai modifica da soli? In entrambi i casi a mantenere la scrittura di eccellente qualità , è raro
vedere un bel blog come questo di oggi .

Look at my web page :: book of ra deluxe

Anonymous said...

I refuse to be held accountable if anyone should
fail to yield to Victory Storm King's power. All you need is to follow the instructions cautiously.
Initially, you have to obtain the application from the limera1n.com.


Check out my web-site :: cydia ios 7 - ,

Anonymous said...

I am curious to find out what blog system you happen to be using?
I'm having some small security issues with my latest site and I would like to find something more safe.

Do you have any suggestions?

Look at my web-site - Clash of Clans Cheats (www.reddit.com)

Anonymous said...

I like the valuɑble information you supply
for your articles. I'll bookmɑrk your blog and teѕt again right
hewre freգսently. I'm sliggtly sure I will learn a lоt of new stսff proper here!

Best oof luck for tthe following!

My web page :: Youtube Good Golf Swing Tips

Anonymous said...

I think this is one of the most important info for me.
And i'm glad reading your article. But want to remark on some
general things, The site style is wonderful, the articles is really
great : D. Good job, cheers

Here is my web blog Deer hunter 2014 Cheats

Anonymous said...

WՕW just whаt I wаs searching for. Came herе by searching ffor email marketing

Stop by my page secured credit card

Anonymous said...

Hi there, You've done a great job. I'll certainly digg it and personally recommend to my friends.
I'm sure they'll be benefited from this site.

my site; air conditioning katy texas

Anonymous said...

Hey I am so delighted I found your blog page, I really found you by error, while I
was searching on Yahoo for something else, Anyways I am here now
and would just like to say kudos for a remarkable post and a all round exciting blog (I also love the theme/design), I don't have time
to browse it all at the moment but I have book-marked it and also included your RSS feeds, so when I have time
I will be back to read more, Please do keep up the great work.


Feel free to visit my web site - Womens Nike Air Max 87

Anonymous said...

Article writing is also a excitement, if you know afterward you can write or else
it is complicated to write.

Here is my web blog :: Fotografia Ślubna Poznań
()

Anonymous said...

Are you wondering how Amazon can sell a device that can get online without monthly fees or a contract that locks you in. The hotel Hilton Quebec now features an Executive Lounge on the top floor.

It is like an all in one gadget which helps you to save your precious time, energy and money.


Review my homepage - Free wifi hack

Anonymous said...

Wow, that's what I was exploring for, what a information! existing here
at this weblog, thanks admin of this web site.

Here is my blog - free cash giveaways online; ,

Anonymous said...

Hello There. I found your blog using msn. This is an extremely well
written article. I will be sure to bookmark it and return to read more of your
useful info. Thanks for the post. I will certainly return.

Here is my weblog ... dental hygienist salary; ,

Anonymous said...

Pretty nice post. I just stumbled upon your weblog and wanted to say
that I have really enjoyed surfing around your blog posts.
After all I'll be subscribing to your feed and I hope you write again soon!

Also visit my web page; gas log Fires melbourne

Anonymous said...

Nice post. I was checking constantly this blog and I'm impressed!

Extremely useful information specially the last part :
) I care for such info a lot. I was looking for this certain info for a very long time.
Thank you and good luck.

Feel free to surf to my weblog Pattek

Anonymous said...

louis vuitton outlet, sac longchamp, ralph lauren pas cher, replica watches, louboutin outlet, louboutin shoes, christian louboutin outlet, prada outlet, ugg boots, longchamp pas cher, tiffany and co, louis vuitton, louboutin, air jordan pas cher, tory burch outlet, cheap oakley sunglasses, nike outlet, polo ralph lauren outlet, ray ban sunglasses, polo ralph lauren outlet, louis vuitton outlet, nike air max, replica watches, louis vuitton, air max, longchamp outlet, michael kors, oakley sunglasses, chanel handbags, nike free, nike roshe run, oakley sunglasses, burberry, tiffany jewelry, ray ban sunglasses, kate spade outlet, prada handbags, oakley sunglasses, nike air max, louis vuitton, louboutin pas cher, uggs on sale, ray ban sunglasses, oakley sunglasses, longchamp, jordan shoes, gucci outlet, ugg boots, nike free, longchamp outlet

mohamed abdo said...


15.شركه مكافحه البق في دبي
16.شركة مكافحه صراصير في دبي
16.شركة مكافحه النمل الأبيض بدبي
17.شركة مكافحه الأفات بدبي
18.شركه مكافحه البرص في دبي
19.شركة مكافحه حمام بدبي
20.شركة مكافحه الحشرات بالشارقه

mohamed abdo said...


1.شركة تنظيف سجاد دبي

2.شركة تنظيف في دبي

3.شركة تنظيف كنب دبي

4.شركة تنظيف الستائر بالبخار دبي

5.شركة مكافحه حشرات في دبي

6.شركة تنظيف المطابخ دبي

7.شركة تنظيف فلل دبي