Исключение произошло при переодевании в результате результатов запроса для контекста типа 'myproject.data.sqlserver.sqlServerContext'.
system.invalidoperationExexception: Br /br /br /br /b /br /br /br /b /br /br /b /br /br /blote quote quote quote 'br /br /blote' Br /blote 'Br /b /blote' blote 'blote' blote 'blote' bloet /> Когда я заполняю производный класс, базовый класс также отображается, но я пытался отделить отображение для двух. class = "lang-cs prettyprint-override">
Код: Выделить всё
[Browsable(false)]
[Bindable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Column("img")]
public byte[]? Img { get; set; }
< /code>
The thread's last activity is on Oct 31, 2019, at 14:52.
However, since I am currently in C# 13-.NET 9:
Version
Original release date
.NET 9
November 12, 2024
Source: .NET и .NET CORE LIFECYCLE, каковы правильные номера версий для C#?, Что нового в C# 13. Деривация: < /p>
Класс может предотвратить от него других классов, или от любого из его членов, объявляя себя или члена как герметичный. < /p>
< /blockquote>
В соответствии с герметичным (c# storming): < /p>
. Модификатор на методе или свойстве, который переопределяет виртуальный метод или свойство в базовом классе. Это позволяет вам позволить классам выходить из вашего класса и не допустить, чтобы они переопределили конкретные виртуальные методы или свойства.[Keyless]
public class PlainTextList : ImgList
{
// other properties here...
[Column("name")]
public string? Name { get; set; }
[Column("img")]
sealed protected override byte[]? Img { get; set; }
}
[Keyless]
public class ImgList
{
[Column("id")]
public string? ID { get; set; }
[Column("img")]
protected virtual byte[]? Img { get; set; }
}
< /code>
Наследние класса работает, но на моем кодех на странице Razor я получаю: < /p>
'plaintextlist.img 'недоступен из-за его уровня защиты (cs0122) < /p>
< /blockquote>
Исключение произошло при переходе на результаты запроса для контекста типа 'myproject.data.sqlserver.sqlserverconcontext. Операция.[code]public async Task PTListFromSqlAsyncList(string spName, Dictionary parameters)
{
var paramDefs = SQLServerInnerHelper.GlobalWithoutOutputParams();
SqlParameter[]? sqlParameter = MinimalDbSettings.SPArrayOfTuplesAndDictPreScale(paramDefs, parameters);
var sqlParam = MinimalDbSettings.SQLParamLessDynamic(spName, sqlParameter);
return await _context.PlainTextList
.FromSql(sqlParam)
.ToListAsync();
}
public async Task
@a.Name
@*Other data here...*@
}
Image @SortIcon("Img")
Name @SortIcon("Name")
@*Other header here...*@
}
Код: Выделить всё
private async Task LoadPlainTexts()
{
var sQLServerHelper = new SQLServerHelper(context);
pTList = null; // ensure spinner shows
StateHasChanged(); // force re-render to show spinner
var spParam = SQLServerInnerHelper.SomeGlobalMethodRazorPageParam(key: "PLAINTEXT_LIST");
pTList = await sQLServerHelper.PTListFromSqlAsyncList("testSP", spParam);
pagination.TotalRecords = pTList.Count;
if (pTList is null)
{
NavigationManager.NavigateTo("notfound");
}
StateHasChanged();
}
private async Task LoadImages()
{
var sQLServerHelper = new SQLServerHelper(context);
imgList = null; // ensure spinner shows
StateHasChanged(); // force re-render to show spinner
var spParam = SQLServerInnerHelper.SomeGlobalMethodRazorPageParam(key: "IMG_LIST");
imgList = await sQLServerHelper.ImgListFromSqlAsyncList("testSP", spParam);
if (imgList is null)
{
NavigationManager.NavigateTo("notfound");
}
StateHasChanged();
}
< /code>
В моем SP у меня есть две функции, для списка простого текста и списка данных файла. Мой упрощенный скрипт: < /p>
PLAINTEXT_LISTКод: Выделить всё
SELECT id, name, {some_plain_text_here} FROM SomeTable
< /code>
{some_plain_text_here}Код: Выделить всё
IMG_LISTКод: Выделить всё
SELECT id, img FROM SomeTable
< /code>
It shows that using sealed modifier for my particular use case isn't working as expected. The system design I was aiming for is to fetch separate instances for a list of plain text and a list of file binary data. Then, on the application layer, I will merge those records into a single list. However, the rendering is asynchronously separated for plain text and file data, which makes for a more user-friendly experience.
I used inheritance* to merge two classes, and I used sealed modifier because it would help.
I thought that if I enforced inheritance on the data class models, I could separate the mapping in EF Core during the database response. I also thought that I could seamlessly disseminate the fields to their corresponding components asynchronously. This would have rendered the list of plain text first, then the image list, which would actually be a single list. However, I was wrong with this concept.
If I put the img property in the PLAINTEXT_LISTКод: Выделить всё
SELECT st.id, st.name, sot.img {some_plain_text_here}
FROM SomeTable AS st
INNER JOIN SomeOtherTable AS sot ON sot.id = st.id
< /code>
The T-SQL script is for demonstration.
My Blazor web app runs smoothly, but the separation of concerns for plain text and file data that should be separately asynchronously rendered is not implemented properly. The plain text and file data are rendered at the same time, or the plain text is still bound to the file model class.
I was surprised because I thought that the mapping in EF Core separates plain text and file data records that are provided by the SP. In my global helper, the base and derived classes are specified separately and based on their corresponding class type.
I now understand the intervention of the @foreach (var a in SortedProdList!)Я был открыт для новых перспектив, даже без использования наследования; Моя цель состоит в том, чтобы правильно отобразить свойства, при этом асинхронно два класса для простых текстовых и файловых данных. Сначала будет отображаться простой текст, а затем будет следовать файл изображения, и это один список. Можно ли работать, как я могу пропустить свойства базового класса при картировании в EF Core, а затем позвонить в эти пропущенные свойства позже на коде переднего/заднего времени?
Подробнее здесь: https://stackoverflow.com/questions/797 ... text-first
Мобильная версия