DataService Entity Framework

Dec 3, 2010 at 10:12 AM

I have created a abstract repository layer for my data access

And i know i need to create viewmodels from my entity classes.

I generated Self tracking entities from my model however with Cinch it seems like that is useless cause the viewmodels are the actual data objects that will be used in the user interface.

Should i still be able to use STE's even when translating between viewmodel and entity?

 

Where should the translating between the 2 happen? should the BBL (As in viewmodel) be the one translating ?

Also is there a way of maybe auto translating between viewmodel -> entity ?

Coordinator
Dec 3, 2010 at 10:27 AM

I can not answer this, Cinch is a MVVM framework that is all. Your model and ViewModel design is up to you. There are many articles showing the Cinch features, but any more than that I can not say. 

One thing though, are you using disconnected architecture if so, tracking changes in Entities is probably no good at all anyway.

Generally what I do these days is have a ViewModel property for each of the Model properties and write to a Model object from the ViewModel.

Dec 3, 2010 at 12:55 PM

Do you then only translate to model object ( in my case model object would be an STE/POCO entity ) when saving changes or do you keep an internal model in the modelview in sync with the properites of the model view?

In the examples you seem to translate only which i think would be fine,

 

Dec 3, 2010 at 2:59 PM

i am trying to set up a View but i get errors regarding the  namespaces for xaml

 

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:CinchV2="clr-namespace:Cinch;assembly=Cinch.WPF"
    xmlns:meffed="http:\\www.codeplex.com\MEFedMVVM"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"            
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    mc:Ignorable="d"
    xmlns:local="clr-namespace:ZebraDesktopClient"
    x:Class="ZebraDesktopClient.DataView"
    d:DesignWidth="640" d:DesignHeight="480"
    meffed:ViewModelLocator.ViewModel="DataViewModel">

 

i now get error on the last meffed line that the namespace does not contain a viewmodellocator definition.

 

Coordinator
Dec 4, 2010 at 8:12 AM

Just follow what the example does and all should be cool. You are referencing Meffed Dll right?

 

And as far as ViewModel goes say I had a LINQ to Entities model that looked like this

 

public class Person{ public int SomeField { get .... set .... }}

I would create a ViewModel that looked like this

public class Person
{
	public int SomeField
	{
		get ....
		set ....
	}
}

I would create a ViewModel that looked like this

public class PersonViewModel : Cinch.ValidatingViewModelBase (say)
{
	private Person currentPersonModel;

	public int SomeField
	{
		get { return currentPersonModel.SomeField;}
		set { currentPersonModel.SomeField = value }
	}
}

 

Dec 5, 2010 at 1:10 PM

ah right, but then you cannot  use all the datawrapper stuff right?


I did get the view to work, somehow in blend it did not work if i did not first load the xaml in visual studio (maybe the referenced assymble was not loaded yet in blend )

 

Coordinator
Dec 5, 2010 at 5:33 PM

There really is a million ways to skin a cat, another way could be do it the way I do in CinchV2 demo apps where I do use DataWrapper<T> then on save say, you convert ViewModel props into EntityFramework based object then you get of both worlds.

 

Its honestly up to you

Dec 5, 2010 at 7:07 PM

i understand that, but as i am new to the MVVM model and Cinch i am just wondering what the normal usage of the architecture would be.

 

I think i will go for converting between viewmodel and the entity world, its a more seperated model and also allows me to use all the datawrapper powers.

Right now i am creating some simple generator that will turn my entities into xml for your generator. maybe once i perfect this i could get a place in the cinch generator?

How would you handle navigating properties in mvvm? viewmodel which references other viewmodels?

Example Employee entity references Company entity,

would this also result in EmployeeViewModel having a ref to a CompanyVIewModel?

 

 

Coordinator
Dec 6, 2010 at 6:22 AM
iceball12 wrote:

How would you handle navigating properties in mvvm? viewmodel which references other viewmodels?

Example Employee entity references Company entity,

would this also result in EmployeeViewModel having a ref to a CompanyVIewModel?

 

Yes that is what we would normally do.

 

As far as converting back to Model, I would only do that on Save. Honestly I can not say too much, every app is different