开发者

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

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 开发者_如何学Goit, 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?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜