Wpf Dynamic UI – Hello Entity quickstart guide.

Requirements:

  • Visual Studio 2010.
  • Nuget package manager

 

Scope

With this how-to you will be able to create customized LinqToEntity data application based on WpfDynamicUI and deliver a working user interface in shorter time compared to standard development.

 

Basics

Linq to entity – or more general a data handling - application needs at least 3 layer to be implemented.

These layers are the

  • Data access
  • Data service
  • User interface

Now lets see what these layers means and how should it be implemented

User interface

The user interface layer must complete the end user exprience requirement. It must handle interaction logic between the business model and end user interaction.

With WpfDynamicUI the User interface is provided out of the box, so we need to focus on the remaining two only.

 

Data Access

For data access the trivial solution is to design your own database and using LinqToEntity database first option generate the strongly typed data access layer using Visual Studio 2010 data access generation functionality.

 

Data service

For data service the WpfDynamicUI LinqToEntity sample provides a re-usable source code for building Data service on the top of the generated data access layer.

 

Solution

Data service for a LinqToEntity application could be abstracted as a solution for Listing and Displaying the entities.

Based on the entity Status we need an Editor display, a New display, and a Delete display.

For the Listing the trivial paging and filtering list solution could make the work.

 

Now see how Category entity models are implemented.

public class CategoryDelete : EntityDeleteModel<Category>
{
[Editable(false)]
public int CategoryId { get; set; }

[Editable(false)]
[StringLength(50)]
public string Name { get; set; }

[Editable(false)]
[StringLength(1000)]
public string Description { get; set; }
}
public class CategoryNew : EntityNewModel<Category>
{
[Required()]
[StringLength(50)]
public string Name { get; set; }

[StringLength(1000)]
public string Description { get; set; }
}
public class CategoryDetails : EntityDetailsModel<Category>
{
[Editable(false)]
public int CategoryId { get; set; }

[Required()]
[StringLength(50)]
public string Name { get; set; }

[StringLength(1000)]
public string Description { get; set; }
}
public class CategoryList : EntityRiportModel<Category>
{
[Display(AutoGenerateFilter = true)]
public string FilterName { get; set; }

protected override IOrderedQueryable<Category> ProvideQuery(System.Data.Entity.DbContext dbContext)
{
return from c in dbContext.Set<Category>()
orderby c.Name
select c;
}

protected override void OnPropertyChanged(string propertyName, object before, object after)
{
if (propertyName.StartsWith("Filter"))
{
Riport.Filter = BuildFilter();
}
base.OnPropertyChanged(propertyName, before, after);
}

private Expression<Func<Category, bool>> BuildFilter()
{
Expression<Func<Category, bool>> condition = c => true;

if (FilterName != null)
condition = condition.And(c => c.Name.Contains(FilterName));

return condition;
}

public static void Categories(WorkspaceModel workspaceModel)
{
BusinessApplication.Instance.OpenModel(() => new CategoryList());
}
}

As each base model is inherited from WpfDynamicUI Model base class it is discovered by the application library.

 

The remaining task is only to write all the entity handler classes and compile the solution.

Hitting F5 and enjoy.

 

Listing categories View

image

Editing category View

image

Creating new category View

image

 

For complete source check out SVN source @trunk/samples/HelloEntity path.

Last edited Apr 15, 2012 at 9:40 PM by csizo, version 3

Comments

No comments yet.