Csla.DataPortalException: 'DataPortal.Create failed (Csla.ReadOnlyListBase... #3679
Replies: 2 comments 4 replies
-
Additional info: The AudStockAdjList Class create I tried as follows too..Did not work either: [Create, RunLocal] I'm missing something simple..but I cant see what. My issue is How do you use Dependency injection in a ReadOnlyList with create and Fetch? |
Beta Was this translation helpful? Give feedback.
-
Hello @PhillipGroen I've just finished migrating my entire application from Csla 4.5 to 7.0.3. Below, I'm copying a ReadOnlyList class, written in C#, as an example that works perfectly for a root class Grandfather that has a child class Father which in turn has children. This class retrieves the root class and all its children, etc., the complete graph. This class shares the Criteria class defined in the GrandfatherInfo class to avoid duplicating filters. I hope you find it useful. #region [Generation_Info]
/* ===============================================================================================================
* Solution : Breintek.Retails.B2B
* Generator : 1.0.1.3 (30/01/2024 23:00:00)
* ---------------------------------------------------------------------------------------------------------------
* Business Class : AbueloReadOnlyList (Root)
* Namespace : Breintek.Retails.B2B.Library.Test
* DatabaseObject : TB_TEST_ABUELOS (Table)
* Stored Procedure : SP_TEST_ABUELOS
* ---------------------------------------------------------------------------------------------------------------
* Path: D:\Desarrollo\BreintekB2B\Breintek.Retails.B2B\Breintek.Retails.B2B.Library\Test\AbueloReadOnlyList.cs
* ---------------------------------------------------------------------------------------------------------------
* Modificaciones : 13/02/2024 12:25:38
* =============================================================================================================== */
#endregion [Generation_Info]
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using Csla;
using Csla.Rules;
using Breintek.Core;
using Breintek.Core.Classes;
using static Breintek.Core.Common;
using Breintek.Retails.B2B.Shared.Test.Interfaces;
using Breintek.Retails.B2B.Shared.Test.LibraryDto;
namespace Breintek.Retails.B2B.Library.Test
{
[Serializable]
public partial class AbueloReadOnlyList : ReadOnlyListBase<AbueloReadOnlyList, AbueloInfo>
{
#region [Factory_Class]
public class Factory
{
#region [Constructor]
private IDataPortal<AbueloReadOnlyList> _dataPortal;
public Factory(IDataPortal<AbueloReadOnlyList> dataPortal)
{
_dataPortal = dataPortal;
}
#endregion [Constructor]
#region [Fetch]
public async Task<AbueloReadOnlyList> GetAsync(AbueloSelectDbTypes selectDbType, string customFilters = null)
{
return await _dataPortal.FetchAsync(new AbueloInfo.FilterCriteria(DbActionTypes.Select, selectDbType, customFilters));
}
public async Task<AbueloReadOnlyList> GetAsync(AbueloInfo.FilterCriteria filterCriteria)
{
return await _dataPortal.FetchAsync(filterCriteria);
}
public async Task<AbueloReadOnlyList> GetAsync(Decimal abueloId, AbueloSelectDbTypes selectDbType, PadreInfo.FilterCriteria padreFilterCriteria, string customFilters = null)
{
return await _dataPortal.FetchAsync(new AbueloInfo.FilterCriteria(abueloId, DbActionTypes.Select, selectDbType, padreFilterCriteria, customFilters));
}
public async Task<AbueloReadOnlyList> GetAsync(AbueloDto abueloDto, AbueloSelectDbTypes selectDbType, string customFilters = null)
{
return await _dataPortal.FetchAsync(new AbueloInfo.FilterCriteria(abueloDto, DbActionTypes.Select, selectDbType, customFilters));
}
#endregion [Fetch]
}
#endregion [Factory_Class]
#region [Dataportal_Methods]
#region [Fetch]
[Fetch]
private void Fetch(AbueloInfo.FilterCriteria filterCriteria, [Inject] IAbueloDal dal, [Inject] IChildDataPortal<AbueloInfo> dataPortal)
{
try
{
#region [TryFetchData]
IsReadOnly = false;
AbueloDto abueloDto = new AbueloDto();
Csla.Data.DataMapper.Map(filterCriteria, abueloDto, true);
var data = dal.FetchList(abueloDto, (AbueloSelectDbTypes)(filterCriteria.OptionSelector ?? AbueloSelectDbTypes.SelectAll), filterCriteria.CustomFilters).Select(d => dataPortal.FetchChild(filterCriteria, d));
this.AddRange(data);
IsReadOnly = true;
#endregion [TryFetchData]
}
finally
{
dal.CloseConnection();
}
}
#endregion [Fetch]
#endregion [Dataportal_Methods]
}
} |
Beta Was this translation helpful? Give feedback.
-
I am at my wits end. I cannot for the life of me get CSLA to work when Im trying to understand CSLA Ver 7 with dependency injection.
I get the following error when I want to Create the object:
Csla.Server.DataPortalException: 'DataPortal .Create failed on the server'
Expanded Error:
Csla.DataPortalException: 'DataPortal.Create failed (Csla.ReadOnlyListBase`2[[SmartTradeCsla.Library.AudStockAdjList, SmartTradeCsla.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[SmartTradeCsla.Library.AudStockAdjListItem, SmartTradeCsla.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Create)'
AudStockAdjList is the "collection" object while "AudStockAdjListItem" is the items in the collection.
I can't get CSLA sample code to even get the point of CREATING an object..let alone going to the database using Fetch
WHAT am I doing wrong? Please Help:
.
The code creating the object: (it is in VB in order for me to maybe understand it more clearly but it would be done in C# at the end)
The code for AudStockAdjList:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Csla;
using Csla.Server;
using SmartTradeCsla.Dal;
namespace SmartTradeCsla.Library
{
[Csla.Server.ObjectFactory("SmartTradeCsla.Dal.SQL2019Express.AudStockAdjListDal, SmartTradeCsla.Dal.SQL2019Express")]
[Serializable()]
public class AudStockAdjList : ReadOnlyListBase<AudStockAdjList, AudStockAdjListItem>
{
private void Create([Inject] IAudStockAdjListDal dal, [Inject] IChildDataPortal itemInfoPortal) { }
}
The AudStockAdjListItem looks like this:
[FetchChild]
private void Fetch([Inject] SmartTradeCsla.Dal.AudStockAdjListItemDTO item)
////private void Fetch(SmartTradeCsla.Dal.AudStockAdjListItemDTO item)
{
}
Beta Was this translation helpful? Give feedback.
All reactions