RIA Services: Extend an entity using a custom class that's also referenced in main project - wcf-ria-services

Here's my situation. I have a "Cities" table in a database that has each city's name, latitude, and longitude. In a silverlight project I'm developing, I need to bind to the city's location, which needs to be some sort of encapsulated form of latitude + longitude. So, to do this, I've made a Location object. I actually need this Location object in general in my silverlight project since the whole project revolves around mapping, so it makes sense for it to be there.
The problem is I want to extend my City object (from the Entity Framework in RIAServices) with a Location property, but I can't do that from my silverlight project since the generated code of RIAServices declares the City object as sealed. Therefore, it seems I need to extend City with a partial class in RIAServices.Web, but to do that, it needs a reference to my Location object, which is back in my main silverlight application. I suppose I could have Location in a separate assembly and have both my silverlight app and RIAServices.Web reference it, but isn't bad design to have RIAServices reference any specific application files like that?
So the problem is this: my entity framework needs the Location object, and my silverlight app also needs it - how to do I share this common class between the two?
Thanks for all the help - I'm really trying to follow a good design pattern here, so I didn't want to hack anything to get it to work.

I think I just figured it out: put Location.cs in RIAServices.Web, but rename it to Location.shared.cs. Now RIAServices.Web will automatically copy it over to RIAServices in its code generation, and I can reference it in my silverlight project (which already references RIAServices). I can also extend my City object back in RIAServices.Web with a Location property since Location.cs is location in RIAServices.Web already. Hooray!
(Does anyone see any design issues with this solution?)

Related

add scaffolded item wizard cannot resolve data model class

everyone.
I'm trying to create new Scaffolded item for simple ASP.NET Wep API application which should be based on domain object class and DbContext derivative in separate assembly. The assembly is in the solution, target app has a reference to it (and manually created code which invokes the classes from my lib is build up without any errors) and, obviously, the classes I've mentioned have access modifier public.
The problem is wizard for creating new scaffolded item cannot see my model classes. (By the way, when the model classes were in another ASP.NET MVC5 app the wizard worked well.) I'm using Visual Studio 2013 Update5.
How to fix this? Any workaround would be helpful too!
Sorry for disturbing.
the origin of the problem seems to be that I've move my data model classes from ASP.NET MVC app into my class library in wrong way.
I've not just cut/paste them, but copy-paste, cut-paste (confirmed replacement).
this is the only thing which could cause the problem (although I still don't know the details).
Never the less I've started from the beginning again and cut/past the data model files initially - everything seems to work fine now.

Using Mogenerator

I've have been using catagories up until now but with the start of a new project I had a look around for new toys to play with and found mogenerator.
I've managed to generate the _entity and entity files, great. But now what?
Am I supposed to put all my code in entity? Do I have to manually add all the new properties now that I cant use the generate nsmo subclass? How do I use the additional methods in _entity, must I import the _entity or the entity files or both?
So for anyone encountering the same problem.
Things seemed to be going wrong because the Entity classes should inherit from the _Entity class. I didnt pick this up from any of the guides but it seems obvious now! Then the Entity class can be a blank implementation if you like.

Migrate custom Facebook util library to Yii framework

I have a facebook app developed in plain PHP, I'm migrating the app to YII framework.
The thing is that I use a class call "utilsFacebook" where I have the object facebook(of the fb sdk) and all the methods that I need to get data from facebook, getUserId, getUserFriendList, etc.
I don't know how to handle all the operations that I do in utilsFacebook with Yii.
Create a controller with the functions of utilsFacebook is the correct think to do?
Every time that I instance the controller would create a new Facebook object, Should I store that object in a SESSION to get a better performance or is a bad idea?
Q. Create a controller with the functions of utilsFacebook is the correct think to do?
Having done a facebook app using yii as the framework, i would recommend you to make this library either a component, or an extension.
But definitely don't put these functions in the controller directly. Whenever a controller needs them call the functions using your custom facebook util class.
Components can be put in the folder: projectrootfolder/protected/components
Extensions can be put in the folder: projectrootfolder/protected/extensions
If you don't believe that either of these make semantic sense, you can always create a new folder within protected, say utils and put the class there. However i think extensions is the best way to go.
Q. Should I store that object in a SESSION to get a better performance or is a bad idea?
I don't think it's necessary to store the object in a session, because there will be no visible performance gain. Further you'll complicate your code unnecessarily.
What i had done was, created an app level component and used this component throughout the app, in any controller.
Example:
In your application's config, protected/config/main.php :
'components'=>array(
'fbHelper'=>array( // gave the component this name
'class'=>'ext.utils.FacebookHelper', // had stored the helper class in extensions/utils folder
'parameter1'='somevalue',
// more parameters
),
// standard yii app components
),
This will allow you to use the component like this: Yii::app()->fbHelper->getFriends();
Take a look at the facebook-opengraph extension, which could help you, on the way.

How to add core data classes to a framework in iOS

I am trying to create a framework out of my existing codebase for the purpose of reuse. I have a exmaple.xcdatamodeld class which in turn contains some core data classes. I have added this entire exmaple.xcdatamodeld class into my new framework. But i am getting an error which says that some of the classes in my exmaple.xcdatamodeld are missing. (Example:classname.h file not found). Am i doing something wrong while adding the entire core data class? Can anyone help me out with my problem...
I have taken this link as a reference while creating the framework
edit : I am not getting the option of adding all the core data classes individually. It seems i can add only the complete datamodel file. PLease refer the screenshot below.
exmaple.xcdatamodeld is your data model. If it refers to any classes that you've created (which will be subclasses of NSManagedObject), you'll need to include the source files (.h/.m files) for those classes in your framework.
The .xcdatamodeld file is just the model, a serialized version of the NSManagedObjectModel. It does not contain any classes.

How do I get my Objects to work in ASP.NET MVC2

I'm rather new to MVC2 (never been in MCV1) though I'm a WebForms developer for some years now...
in my MCV 2 start project I created a App_Code folder that I would put my Business Classes on it, I also add 2 References to 2 DLLs used for the API I'm about to use.
But I don't get Intellisense on the referenced objects
What am I doing wrong?
alt text http://www.balexandre.com/temp/2010-07-28_1343.png
Is this so much different from the WebForms part?
Added
Even if I put the Object in Models instead App_Code (where I normally put all code in WebForms) I still don't get the normal intelisense, so... it just tells me that something is wrong ... dang! MVC is hard! I probably should do this in WebForms...
alt text http://www.balexandre.com/temp/2010-07-28_1509.png
This has nothing to do with MVC2, and everything to do with you're doing it wrong. I can tell that its a possibility, as you're using App_Code (I mean, who does that?). I'd definitely suggest backing up and reading some MVC tutorials, as it IS much different (although not in the way you're asking about).
I'm not exactly sure WHAT you're doing wrong, however. It might bethat PerceptiveMCAPI is internal to the assembly, it might be because there is a bug in VS, it might be that you haven't imported the correct namespace... it could be a number of different things.
I'd do the following: 1) load the assembly in reflector and make sure you have the namespace and type name and that it is public 2) use the fully qualified name of the type 3) compile, check all errors and 4) restart VS.
If all else fails, Connect.
See the Models directory -- that's where your model classes would go, assuming the class is a view model class. Having said that, it should be able to pick up and provide intellisense for whatever references you add. App_Code isn't really intended for a Web Application project (the type used by MVC) where the code is compiled statically, but rather for a WebSite where the code is compiled dynamically at runtime. It could be the "special" nature of the directory that is causing the problem because it doesn't fit the project type. You might try simply creating a different directory (if Models isn't appropriate) and not use the special App_Code directory for your code. A separate class library project with a project reference in the web application would be another alternative and is the one I usually use for non-viewmodel/controller code.