Please tell me why i can't add
using Csla.Wpf
in my references i have Csla and csla.xaml
?
Thanks
That namespace doesn't exist in CSLA 4, it has been replaced with Csla.Xaml.
Thanks, but how can i use Csla.Validation; on WPF? Is it possible, because my classes are done for Windows form project.
Thanks again
What version of CSLA are you using? Csla.Validation doesn't exist in CSLA 4 either, it has been replaced by Csla.Rules.
If you are using CSLA .NET 3.8 you can use the business rules in your objects on both Windows Forms and WPF.
If you are using CSLA 4 you can use the business rules in your objects on both Windows Forms and WPF, but you will probably want to have different collection/list types for Windows Forms, because the default collection base types now support WPF (3.8 doesn't support WPF very well for collections).
But the collection issue has nothing to do with business rules - they work on all platforms including Windows Forms and WPF.
How you display the business rules in the UI is quite different between Windows Forms and WPF. In Windows Forms you probably use the ErrorProvider control. You can use the built-in IDataErrorInfo support in WPF too, but it is relatively limited, and you probably want to use the PropertyStatus control in the Csla.Wpf namespace.
In CSLA 4 the PropertyStatus control is moved to the Csla.Xaml namespace and assembly, but it works the same.
The CSLA 4 MVVM video series should be very helpful to you as you learn how to use CSLA with WPF.
I'm using CSLA 4.0., here is my code. I have problem on underlined rows. But when i'm on windows form application everything is ok.
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Rules;
using InTaxiHome.Library;
using Csla.Xaml;
using Csla.Rules.CommonRules;
[Serializable()]
public class UliciSkEnInfo : Csla.ReadOnlyBase<UliciSkEnInfo>
{
#region Business Properties and Methods
//declare members
private int _id = 0;
private string _ulica = string.Empty;
private bool _active = false;
private byte[] _lastChanged;
[System.ComponentModel.DataObjectField(true, false)]
public int Id
{
get
{
CanReadProperty("Id", true);
return _id;
}
}
public string Ulica
{
get
{
CanReadProperty("Ulica", true);
return _ulica;
}
}
public bool Active
{
get
{
CanReadProperty("Active", true);
return _active;
}
}
protected override object GetIdValue()
{
return _id;
}
#endregion //Business Properties and Methods
#region Factory Methods
private UliciSkEnInfo()
{ /* require use of factory method */ }
public static UliciSkEnInfo GetUliciSkEnInfoById(int id)
{
return DataPortal.Fetch<UliciSkEnInfo>(new Criteria(id));
}
public static UliciSkEnInfo GetUliciSkEnInfo()
{
return DataPortal.Fetch<UliciSkEnInfo>(new Criteria());
}
public static UliciSkEnInfo GetUliciSkEnInfo(SafeDataReader sdr)
{
return DataPortal.Fetch<UliciSkEnInfo>(new Criteriasafe(sdr));
}
#endregion //Factory Methods
#region Data Access
#region Criteria
[Serializable()]
private class Criteria
{
public int Id;
public Criteria(int id)
{
this.Id = id;
}
public Criteria() {
this.Id = -1;
}
}
[Serializable()]
private class Criteriasafe
{
public SafeDataReader _dr;
public Criteriasafe(SafeDataReader sdr)
{
this._dr = sdr;
}
}
#endregion //Criteria
#region Data Access - Fetch
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Fetch(Criteria criteria)
{
using (SqlConnection cn = new SqlConnection(Database.IntaxiDBConnection))
{
cn.Open();
ExecuteFetch(cn, criteria);
}//using
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Fetch(Criteriasafe criteria)
{
ExecuteFetch(criteria);
}
private void ExecuteFetch(SqlConnection cn, Criteria criteria)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
if (criteria.Id < 0)
{
cm.CommandText = "getUliciSkEn";
}
else {
cm.Parameters.AddWithValue("@Id", criteria.Id);
cm.CommandText = "getUliciSkEnById";
}
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
FetchObject(dr);
//load child object(s)
FetchChildren(dr);
}
}//using
}
private void ExecuteFetch(Criteriasafe criteria)
{
FetchObject(criteria);
}
private void FetchObject(SafeDataReader dr)
{
dr.Read();
_id = dr.GetInt32("Id");
_ulica = dr.GetString("Ulica");
_lastChanged = (byte[])dr["LastChanged"];
}
private void FetchObject(Criteriasafe dr)
{
_id = dr._dr.GetInt32("Id");
_ulica = dr._dr.GetString("Ulica");
_lastChanged = (byte[])dr._dr["LastChanged"];
}
private void FetchChildren(SafeDataReader dr)
{
}
#endregion //Data Access - Fetch
#endregion //Data Access
}
In Csla 4 your property declarations should be like this:
public static readonly PropertyInfoM<string> MyStringProperty = RegisterProperty( x => x.MyString );
public string MyString {
get { return GetProperty( MyStringProperty ); }
set { SetProperty( MyStringProperty, value ); }
}
All the normal processing (security checks, business rules, marking as dirty) will be done automatically for you. There are alternate methods too, LoadProperty and ReadProperty, when you want to bypass the normal behaviors.
This blog post describes the introduction of the new property sytax, but of course Csla 4 has some changes and improvements since they were first introduced in 3.5. http://www.lhotka.net/weblog/CSLANET35PropertyCodeReduction.aspx
Thanks for that, it is really useful. But can you tell where can i find good templates for codesmith for CSLA 4 because every that i found is not ok?
Thank you again
Copyright (c) Marimer LLC