Hi,
Before we give the basic question, I will describe what and how.
Technologies which use:
- NRoute;
- NHibernate;
- RIA Services;
- SQL Server;
I also use Telerik controls.
This Silverlight project looks like this:
Database- SQL Server;
nHibernate - mapping:
<?xml version="1.0" encoding="utf-8"?> <hibernate-mapping assembly="Wspolny" namespace="Model.Entities.Promocje" xmlns="urn:nhibernate-mapping-2.2" default-lazy="true"> <class name="EPromocja" table="Promocja" lazy="1" > <id name="ID"> <generator class="identity" /> </id> <property name="Nazwa"> <column name="Nazwa" sql-type="nvarchar" not-null="true" /> </property> <property name="Opis"> <column name="Opis" sql-type="nvarchar" not-null="false" /> </property> <property name="MiejsceSprawdzania"> <column name="MiejsceSprawdzania" sql-type="int" not-null="false" /> </property> <property name ="OperatorOpiekun"> <column name="OperatorOpiekun" sql-type="int" not-null="false"/> </property> </class> </hibernate-mapping>nHibernate – Entity:
[KnownType(typeof(PromocjaZDatami))]public class EPromocja : EBazowa { public virtual string Nazwa { get; set; } public virtual string Opis { get; set; } public virtual int? MiejsceSprawdzania { get; set; } public virtual int OperatorOpiekun { get; set; } } public class PromocjaZDatami : EPromocja { public virtual DateTime? DataOd { get; set; } public virtual DateTime? DataDo { get; set; } }Binding to RadGridView look's like this:
<telerik:RadGridView SelectedItem="{Binding ZaznaczonaPromocja, Mode=TwoWay}" ItemsSource="{Binding Path=ClientDataSource.DataView}"> ...And ClientDataSource...
public RadDomainDataSource ClientDataSource { get { if (_zrodloDanych == null) { _zrodloDanych = new RadDomainDataSource(); _zrodloDanych.DomainContext = this.DomainContext; _zrodloDanych.AutoLoad = false; _zrodloDanych.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor() { Member = "Nazwa", SortDirection = ListSortDirection.Ascending }); _zrodloDanych.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor() { Member = "DataOd", SortDirection = ListSortDirection.Ascending }); _zrodloDanych.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor() { Member = "DataDo", SortDirection = ListSortDirection.Ascending }); _zrodloDanych.LoadingData += (s, e) => { CzyWczytujeDane = true; e.LoadBehavior = LoadBehavior.RefreshCurrent; }; _zrodloDanych.LoadedData += (s, e) => { CzyWczytujeDane = false; if (Promocja != null) ZaznaczonaPromocja = Promocja; }; _zrodloDanych.QueryName = "PobierzPromocjeZDatami"; //_zrodloDanych.QueryName = "PobierzPromocje"; } return _zrodloDanych; } set { _zrodloDanych = value; NotifyPropertyChanged(() => ClientDataSource); } }And I know that, PobierzPromocjaZDatamialways returns the correct data set.
The problem is that when I start a project, the data is correctly loaded and displayed in RadGridView. But when I added the object EPromocja, and I use SubmitChanges() function, that data is properly collected (they look the same as before, only one object more), but can not be properly displayed.
I get exception in Just-In_Time Debugger:
An unhandled exceptioin ('Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: System.InvalidCastException: Unable to cast object of type 'Model.Entities.Promocje.EPromocja' to type 'Wspolny.DAL.DTO.PromocjaZDatami'.)
I do not know how to bite. Please help!
Regards, Patryk
