New Posts New Posts RSS Feed: Some clarifications...
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Some clarifications...

 Post Reply Post Reply
Author
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Topic: Some clarifications...
    Posted: 20-Apr-2009 at 10:00pm
Hi Ward;

I noticed in the video, you did not select "Create partial files" in OM when you created your DevForce Model. However, in the SL project, in the "Model" directory you created a "Partial" class for customer manually, which as you explained, will only be used in SL client.
a) So, if I was going to have the "Add" and "Delete" capability for employee, I would basically create a new Employee class that drives from the two interfaces and now, I have the ADD and DELETE icons/feature activated. Correct?

b) Now, what if you had also asked the OM create all the partial classes. Will those be primarily used as "Server" logic, if any code was added? I'm trying to formulate how I should organize the solution that client code and server codes run independently.

c) what was the motive behind building this template? Was it as a guideline how we should build and organize or projects and split the codes following the MVVM that is shown in this template? Or was this template designed for people to use it as a template for creating their CRUD routines?

Thanks!
Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Posted: 22-Apr-2009 at 11:38am
Great questions, Ben.
 
Q: Why did I not select "Generate Partial Files"?
A: Because it pollutes the project with class files that don't do anything.
 
Of course I'm speaking from my PERSONAL perspective when I say that. But I really don't like generating a ton of do-nothing files. Your project fills up with a file-per-type and you have no idea whether there is anything material going on in there. This is what gives code generation a bad name.
 
My rule: if you see an entity class file, that means the entity is customized; if you don't, it isn't.
 
It is easy to create a partial class file WHEN YOU'RE READY TO EXTEND THE CLASS WITH SUBSTANCE. In it's entirety that class is: public partial class Customer {...}
 
As far as I'm concerned, this feature is a legacy of our legacy product (Classic) ... which generated the custom class files automatically. There was some justification for that in as much as it was not utterly obvious how to create a custom business object class file (although if I had it to do over again, I'd have preferred providing a Class template).
 
Q: Why is the Customer partial class file in the Silverlight project only?
A: Ahhh .... because I could get away with it?
 
In principle there should be no difference between the entity class on the client and the entity class on the server. So the proper way to do things is to create the Customer partial class on the full DotNet model project (the server project) and and then link to it in the corresponding Silverlight client model project.
 
I cheated to make creation of the templates easier and because there was no harm in cheating. But it certainly deserves explanation.
 
In the Model Explorer, the Customer partial class file has logic for adding and deleting. I only add or delete on the Silverlight client. Because I don't add or delete on the server, I won't miss that functionality in the server version of the model.
 
Q: You mean that "Customer" on the server need not be identical to "Customer" on the client?
A: True.
 
I'm not recommending that per se. I think there is real benefit to maintaining a single model ... with a single definition of each entity that is identical no matter where it executes. 
 
If the application were written entirely in full DotNet, there would be only one model dll. The reason we have two dlls is that it is not possible to create a single assembly that executes on both platforms. We try to work-around that by compiling two dlls from one body of source code. We do our best to simulate a single type (that involves some heavy lifting on our part to map the two "Customer" types).
 
Nonetheless, Customer is really not the same type on both client and server. And, as it happens, you can get away with having two versions of Customer that are not textually the same.
 
This is an opportunity ... and a risk. I prefer not to incur the risk and that's why I encourage the principled approach of having only a single definition of "Customer". But I can think of at least two good reasons for diverging from the "principled" approach.
 
1) Differences between Silverlight and full DotNet drive you to implement your intent differently depending upon the target platform.
 
2) You do not want functionality on one side (client or server) to be available on the other.
 
Case #1 is fairly common. You could have a single class file and distinguish two implementations of the same method using compiler directives (e.g., #if SILVERLIGHT). This gets ugly and hard to maintain. I join many others in preferring to push those differences into separate partial class files. Maybe you call them Customer.SL and Customer.DotNet.
 
Case #2 is more rare. You may have code that should ONLY execute in one environment or the other. Maybe you have a proprietary method that shouldn't be exposed on the client. You could make it a partial method and then have a Customer.ServerOnly partial class file that implements it.
 
Q: What if I had asked the OM to create the partial classes ... Will those be primarily used as "Server" logic?
A: The OM generates both Server class files and Client links ... so your custom logic appears in both models.
 
Again, I never do this. It is certainly convenient that the OM generates the Silverlight links to go with the full DotNet, server-side partial class files. This is not a sufficient benefit to me.
 
BTW, Microsoft Patterns and Practices offers a Visual Studio plug-in to help you maintain the linkage between a DotNet and Silverlight project. It's called the "Microsoft Practices Project Linker" and you can get it from a Microsoft download page. It's part of the Prism stack but quite useful on its own and it can be downloaded independently from that page.
 
Q: Implementing the Add and Delete interfaces on the client enables that feature in the M.E. UI?
A: Yes
 
There is nothing magical about these interfaces, BTW. They aren't part of DevForce and DevForce doesn't itself take a stand on whether you can or cannot add or delete. What you see is a Model Explorer design decision. You are free to emulate it or not.
 
Q: Why did you create this template?
A: So you could build a Model Explorer for YOUR database
 
We could have offered this as sample code (and will do so, if we haven’t already).
 
But we thought that, if you wanted to build a model explorer for your own database, it would be far easier to use a template rather than hack the sample code.
It is no accident that it makes for a neat demo. It’s pretty compelling to be able to deliver that much functionality, from scratch, in less than four minutes. And you get to see the fundamental mechanics of a DevForce-based Silverlight application in one fell swoop.
Q: Is the template our recommendation of best practices?
A: Well, there are some good practices in it
 
This post is already long so I won’t go into them all. But we do show some important practices such as MVVM and encapsulation of persistence operations within a façade class (the PesistenceService). There are some dubious practices too. In a real application I wouldn’t throw everything into one Silverlight project and one Server project.
Ward
Back to Top
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 8:17am
Hi Ward;

Thank you for extensive answer; Had a couple questions on your points.


It is easy to create a partial class file WHEN YOU'RE READY TO EXTEND THE CLASS WITH SUBSTANCE. In it's entirety that class is: public partial class Customer {...}

In EF when you want EF to create your classes from the table(s), you can either select the ALL tables on the TreeView or you can select individual tables. Similarly, for OM, can you add that feature where we can select either all tables or individual tables to be generated? Right now, it's either ALL or NOTHING!


In principle there should be no difference between the entity class on the client and the entity class on the server. So the proper way to do things is to create the Customer partial class on the full DotNet model project (the server project) and and then link to it in the corresponding Silverlight client model project.

So, in the case of ME, the "Model" folder with two interfaces and Customer.cs should actually be in the "Server project"?
I'm trying to formulate a solution structure, so when I usually start a project, I first build the structure of the solution with all the folders and virtual floders and supporting files, before I build an app.
A guideline for building DevForce structure would be very useful! Thanks.


In the Model Explorer, the Customer partial class file has logic for adding and deleting. I only add or delete on the Silverlight client. Because I don't add or delete on the server, I won't miss that functionality in the server version of the model.

So, would be safe to say, actions that are client specific, like above should stay in client?

Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 10:13am
"For OM, can you add that feature where we can select either all tables or individual tables to be generated? Right now, it's either ALL or NOTHING!"
 
That's a feature I'd like to have ... and would have today ... if there weren't attendant complexities. For example, suppose OrderDetails requires a relationship to its parent Order ... so says your EF model. You choose to omit the Order entity. Big problem: you can't create an OrderDetail because EF will object.
 
Now this problem actually exists for EF already. If I had omitted Order while mapping OrderDetail in EF and I tried to create an OrderDetail entity, the database would block the insert. But we decided not to create TWO opportunities for this kind of problem. We figure EF is your mapping tool and our Mapper is just another way to manage (and enrich) the EF mapping. Therefore, while we have this feature on the list ... we have not given it much priority.
 
"in the case of ME, the "Model" folder with two interfaces and Customer.cs should actually be in the "Server project"?"
 
Yes it should ... and the client model project should have a link to it. The way I did it was "lazy". Why don't I just fix it? Because I would have to create and maintain a separate M.E. Server Project Template and probably the wizard that goes with it (right now we leverage the standard DevForce server template and wizard). That didn't seem like an appropriate use of our energies.
 
"Would be safe to say, actions that are client specific, like above should stay in client?"
 
The agilist in me thinks that this is ok. It sure is convenient. There willl be plenty of model functionality that you will never execute on the server even if you think you might want to do so someday.
 
On the other hand (aside: "Would someone show me a two-handed advisor?" - Truman), we really want one model. We want the confidence that we can execute any part of our model on either the client or the server tier if we choose to do so.
 
If there is something that can (or should ) be executed only on a particular tier, that fact can be made explicit by a separate class file (marked ServerOnly or ClientOnly); otherwise the two sides should be the same.
 
Why? Imagine that one day ... after a bad experience in production ... we lose faith in the guard logic on the client. It isn't that that logic is wrong; we haven't had a security breach; but we're not sure that our guard logic is being honored everywhere on the client.
 
So we decide, in the ServerSavingEvent to re-check the validity of the entities and the operations on them before we perform the save. And, in particular, we we want the server to ensure that it does not delete an entity that should not be deleted by this user. 
 
We'd want the same "CanDelete" logic on both client and server, right? We have no reason to believe that the logic should be different do we?
 
Let's face it ... it is trivial to put the partial class on the server ("where it belongs") and link to it from the client. You set that up once and you are done. Then you know that you're logic compiles on both sides and you can write tests on both sides.
 
After dancing around the subject for awhile ... I conclude that the "best" practice is as follows:
  1. Favor implementing the same logic on both client and server
  2. Be explicit when logic executes only on one tier or the other
  3. Isolate such tier-specific logic in partial class files that shout-out their exceptionalism.
Evidently I departed from this practice in my M.E. example.
 
"I'm trying to formulate a solution structure, ... with all the folders and virtual folders and supporting files, before I build an app."
 
Good luck with that. I've been trying to do that for years. I never get it right. I'm not sure that there is a "right" independent of where you are in your development of the application and your understanding of the application requirements.
 
Not that I don't keep trying. And I do think there are choices that make for a good start. I think the folders that you see within the ME project are pretty good.
 
Frankly, the M.E. structure is "right" only for an exploratory application. For example, in almost anything but a demo I immediately separate out the model into its own projects (client and server). You can do that from Day One with the Object Mapper ... as Greg shows in one of his tutorials.  I have 4 project version of M.E. (ME, MEWeb, ME.ClientModel, ME.ServerModel) that I hope to post soon. My app usually evolves into more projects from there as I modularize.
 
Conventionally each Custom Control (see the AniButton) should be in its own assembly so it can be re-used.
 
I'm not trying to dodge this one. I applaud every attempt to provide guidance on solution structure. I have craved such guidance myself.
 
But I was humbled by my experience with CAB (and Cabana) wherein I succumbed to a mad desire to get everything in its ultimate place on day one. I refined it and refined it. In the end, I had a perfect understanding and explanation for every decision. Unfortunately, I was all alone; everone else gave me that "WTF" look. Humbled indeed.


Edited by WardBell - 23-Apr-2009 at 10:17am
Back to Top
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 10:31am
Thank again Ben and Ward.  Ben for the probing and well timed questions, Ward for exposing your depth of knowledge and experience.  It sure helps to have such detail while comming to grips with DFSL.  Keep it up PLEASE.
Back to Top
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 10:55am
Ward, I'm suprised to see with your wealth of knowledge and great writing skill, you're not writting books.

Thanks so much, and I thank Ben [myself] for pushing you to get these answers out of you :-)

Ya, I know what you mean by the "WTF" look! :-)
Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 10:59am
Dominic, I hope you're spending some time reading the guide. As an old vetran in Business Solution provider, it's a joy to see the people who developed DevForce have a great real life "experience". You can tell this product was designed and developed from experience and not theory. So, be sure to read the guide.
Just my two cents!
Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 11:12am

That's a feature I'd like to have ... and would have today ... if there weren't attendant complexities. For example, suppose OrderDetails requires a relationship to its parent Order ... so says your EF model. You choose to omit the Order entity. Big problem: you can't create an OrderDetail because EF will object.


If possible, give us that option and let us be responsible if we don't pick the right combo. The same risk EF took.
If not, then should I generate all and then manually delete the ones I don't want?
Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 11:24am
Hi Ben, If you mean the DF Developer Guide then yes, a good read, done that, and it'll be my consummate & handy reference for the next few years.  As I mentioned in my verbose post last week, and likewise yourself, we still need some more examples that the guide hasn't exposed, albeit, the SL thing is still very fresh so no wonder.  It'll catch up.
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 2:58pm
"should I generate all and then manually delete the ones I don't want?"
 
NO NO NO!
 
Entity Framework designer is good at adding things. It's a PITA when you remove things ... especially classes/tables. The EF designer takes the position that it only adds. Even a column rename is treated as the addition of a new property; the old, unmapped property is left behind for you to manually delete from your model. And that's an easy case.
 
Once you understand how it behaves and what it is telling you when it is unhappy, you can get along with the EF designer just fine. But when you don't know and haven't seen it vomit ... well, you just want to chuck it in the ocean.
 
I strongly recommend that you
  • add entities only as you need them.
  • always back up your EDMX file before any surgery
  • move forward in small bites (especially until you are experienced)
  • Watch our videos on EF maintenance
Greg did a great little video series on basic EF maintenance (scroll to the bottom section of this page).  I was going to do a series on advanced ("hair pulling") scenarios ... such as deleting entities. One of those things I need to get to. I have a decent trick for it ... but it's a trick.
 
BigFish - I'm going to get to your magnum opus real soon. I love it.
Back to Top
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Posted: 23-Apr-2009 at 3:24pm
Ward, perhaps you misunderstood me or I wasn't clear. I was not talking about the EF code generation and EDMX deletion. I was referring to OM creating all the partial classes first and then in the VS explorer I can delete any partial class I don't need, i.e. Employee.cs

Hope this is more clear!
Thanks!


Edited by BenHayat - 23-Apr-2009 at 3:32pm
Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
BenHayat View Drop Down
Groupie
Groupie
Avatar

Joined: 06-Jan-2009
Location: Estero, FL USA
Posts: 86
Post Options Post Options   Quote BenHayat Quote  Post ReplyReply Direct Link To This Post Posted: 27-Apr-2009 at 11:11am
^Bump^
Best Regards!
..Ben

WPF & Silverlight Insider
http://www.MicroIntelligence.Com
Back to Top
WardBell View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Posted: 27-Apr-2009 at 8:10pm
Yes .. Yes .. I know.  Please bear with me.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down