При вставке ServiceInfo вставка не удается. Это не удалось на иностранном ключе JobResult.jobid здесь классы. < /P>
//------------------------------------------------------------------------------
//
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
//
//------------------------------------------------------------------------------
namespace PPISNetWebApi.Models
{
using System;
using System.Collections.Generic;
public partial class ServiceInfo
{
public int ServiceInfoId { get; set; }
public System.DateTime ServiceDate { get; set; }
public int LocationId { get; set; }
public int ServerId { get; set; }
public string WhoRec { get; set; }
public Nullable RelationId { get; set; }
public Nullable DOB { get; set; }
public Nullable Age { get; set; }
public Nullable RaceId { get; set; }
public string Sex { get; set; }
public string Height { get; set; }
public string Weight { get; set; }
public Nullable HairId { get; set; }
public string OtherDesc { get; set; }
public string ServiceComments { get; set; }
public Nullable Signature { get; set; }
public Nullable Hostile { get; set; }
public Nullable ServiceLocLat { get; set; }
public Nullable ServiceLocLon { get; set; }
public string PhotoFileName { get; set; }
public int DocumentJobId { get; set; }
public Nullable RateChg { get; set; }
public int JobResultId { get; set; }
public int ServiceTypeId { get; set; }
public Nullable MailDate { get; set; }
public string MailType { get; set; }
public Nullable RestDel { get; set; }
public string PropDesc { get; set; }
public Nullable DateReturned { get; set; }
public Nullable Amended { get; set; }
public string Title { get; set; }
public Nullable DateEntered { get; set; }
public Nullable TotalJobRevenue { get; set; }
public Nullable TotalCost { get; set; }
public Nullable Notary { get; set; }
public Nullable NoAtt { get; set; }
public Nullable EFilingDate { get; set; }
public string EFileNo { get; set; }
public virtual DocumentJob DocumentJob { get; set; }
public virtual Hair Hair { get; set; }
public virtual JobResult JobResult { get; set; }
public virtual Location Location { get; set; }
public virtual Race Race { get; set; }
public virtual Relation Relation { get; set; }
public virtual Server Server { get; set; }
public virtual ServiceType ServiceType { get; set; }
}
}
//------------------------------------------------------------------------------
//
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
//
//------------------------------------------------------------------------------
namespace PPISNetWebApi.Models
{
using System;
using System.Collections.Generic;
public partial class JobResult
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public JobResult()
{
this.AttReslts = new HashSet();
this.DocumentJobs = new HashSet();
this.ServiceInfoes = new HashSet();
}
public int JobResultId { get; set; }
public string JobResultName { get; set; }
public string JobResultDesc { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection AttReslts { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection DocumentJobs { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection ServiceInfoes { get; set; }
}
}
< /code>
Я попытался добавить строку вручную, разместив JSON в API, используя почтальон < /p>
{
"ServiceInfoId": 0,
"ServiceDate": "2025-09-15T00:00:00",
"LocationId": 16369,
"ServerId": 4,
"WhoRec": "Ann green ",
"RelationId": 1005,
"DOB": "1964-07-30T00:00:00",
"Age": 61,
"RaceId": 9,
"Sex": "female",
"Height": "5ft5 ",
"Weight": "111 ",
"HairId": 9,
"OtherDesc": null,
"ServiceComments": null,
"Signature": null,
"Hostile": null,
"ServiceLocLat": null,
"ServiceLocLon": null,
"PhotoFileName": null,
"DocumentJobId": 15315,
"RateChg": null,
"JobResultId": 1005,
"ServiceTypeId": 1,
"MailDate": null,
"MailType": null,
"RestDel": null,
"PropDesc": null,
"DateReturned": null,
"Amended": null,
"Title": null,
"DateEntered": null,
"TotalJobRevenue": null,
"TotalCost": null,
"Notary": null,
"NoAtt": null,
"EFilingDate": null,
"EFileNo": null
}
< /code>
Я знаю, что в Jobresult должна существовать ценность JobResultId. JobResultid является основным ключом в JobResult. Jobresultid 1005 существует в Jobresult. Я пытаюсь получить сохраненные данные ServiceInfo в базе данных."ExceptionMessage": "The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_ServiceInfo_JobResult\"
< /code>
Я также попробовал ниже код, чтобы ввести строку, но получил тот же результат. < /p>
public async Task CreateServiceInfoAsync([FromBody]ServiceInfo serviceInfo, bool isNewItem)
{
Uri uri = new Uri(string.Format(Constants.RestUrl7, string.Empty));
try
{
string json = JsonSerializer.Serialize(serviceInfo, _serializerOptions);
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
if (isNewItem)
{
response = await _client.PostAsync(uri, content);
Debug.WriteLine(content);
Debug.WriteLine(@"\tServiceInfo successfully sent.");
}
else
response = await _client.PutAsync(uri, content);
if (response.IsSuccessStatusCode)
Debug.WriteLine(@"\tServiceInfo successfully saved.");
}
catch (Exception ex)
{
Debug.WriteLine(@"\tERROR {0}", ex.Message);
}
}
< /code>
Я начинающий программист самоучки и не могу понять это. Чего мне не хватает!
Подробнее здесь: https://stackoverflow.com/questions/797 ... et-web-api
Почему вставка проходит в веб -API .NET .NET. ⇐ C#
Место общения программистов C#
-
Anonymous
1758216243
Anonymous
При вставке ServiceInfo вставка не удается. Это не удалось на иностранном ключе JobResult.jobid здесь классы. < /P>
//------------------------------------------------------------------------------
//
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
//
//------------------------------------------------------------------------------
namespace PPISNetWebApi.Models
{
using System;
using System.Collections.Generic;
public partial class ServiceInfo
{
public int ServiceInfoId { get; set; }
public System.DateTime ServiceDate { get; set; }
public int LocationId { get; set; }
public int ServerId { get; set; }
public string WhoRec { get; set; }
public Nullable RelationId { get; set; }
public Nullable DOB { get; set; }
public Nullable Age { get; set; }
public Nullable RaceId { get; set; }
public string Sex { get; set; }
public string Height { get; set; }
public string Weight { get; set; }
public Nullable HairId { get; set; }
public string OtherDesc { get; set; }
public string ServiceComments { get; set; }
public Nullable Signature { get; set; }
public Nullable Hostile { get; set; }
public Nullable ServiceLocLat { get; set; }
public Nullable ServiceLocLon { get; set; }
public string PhotoFileName { get; set; }
public int DocumentJobId { get; set; }
public Nullable RateChg { get; set; }
public int JobResultId { get; set; }
public int ServiceTypeId { get; set; }
public Nullable MailDate { get; set; }
public string MailType { get; set; }
public Nullable RestDel { get; set; }
public string PropDesc { get; set; }
public Nullable DateReturned { get; set; }
public Nullable Amended { get; set; }
public string Title { get; set; }
public Nullable DateEntered { get; set; }
public Nullable TotalJobRevenue { get; set; }
public Nullable TotalCost { get; set; }
public Nullable Notary { get; set; }
public Nullable NoAtt { get; set; }
public Nullable EFilingDate { get; set; }
public string EFileNo { get; set; }
public virtual DocumentJob DocumentJob { get; set; }
public virtual Hair Hair { get; set; }
public virtual JobResult JobResult { get; set; }
public virtual Location Location { get; set; }
public virtual Race Race { get; set; }
public virtual Relation Relation { get; set; }
public virtual Server Server { get; set; }
public virtual ServiceType ServiceType { get; set; }
}
}
//------------------------------------------------------------------------------
//
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
//
//------------------------------------------------------------------------------
namespace PPISNetWebApi.Models
{
using System;
using System.Collections.Generic;
public partial class JobResult
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public JobResult()
{
this.AttReslts = new HashSet();
this.DocumentJobs = new HashSet();
this.ServiceInfoes = new HashSet();
}
public int JobResultId { get; set; }
public string JobResultName { get; set; }
public string JobResultDesc { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection AttReslts { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection DocumentJobs { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection ServiceInfoes { get; set; }
}
}
< /code>
Я попытался добавить строку вручную, разместив JSON в API, используя почтальон < /p>
{
"ServiceInfoId": 0,
"ServiceDate": "2025-09-15T00:00:00",
"LocationId": 16369,
"ServerId": 4,
"WhoRec": "Ann green ",
"RelationId": 1005,
"DOB": "1964-07-30T00:00:00",
"Age": 61,
"RaceId": 9,
"Sex": "female",
"Height": "5ft5 ",
"Weight": "111 ",
"HairId": 9,
"OtherDesc": null,
"ServiceComments": null,
"Signature": null,
"Hostile": null,
"ServiceLocLat": null,
"ServiceLocLon": null,
"PhotoFileName": null,
"DocumentJobId": 15315,
"RateChg": null,
"JobResultId": 1005,
"ServiceTypeId": 1,
"MailDate": null,
"MailType": null,
"RestDel": null,
"PropDesc": null,
"DateReturned": null,
"Amended": null,
"Title": null,
"DateEntered": null,
"TotalJobRevenue": null,
"TotalCost": null,
"Notary": null,
"NoAtt": null,
"EFilingDate": null,
"EFileNo": null
}
< /code>
Я знаю, что в Jobresult должна существовать ценность JobResultId. JobResultid является основным ключом в JobResult. Jobresultid 1005 существует в Jobresult. Я пытаюсь получить сохраненные данные ServiceInfo в базе данных."ExceptionMessage": "The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_ServiceInfo_JobResult\"
< /code>
Я также попробовал ниже код, чтобы ввести строку, но получил тот же результат. < /p>
public async Task CreateServiceInfoAsync([FromBody]ServiceInfo serviceInfo, bool isNewItem)
{
Uri uri = new Uri(string.Format(Constants.RestUrl7, string.Empty));
try
{
string json = JsonSerializer.Serialize(serviceInfo, _serializerOptions);
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
if (isNewItem)
{
response = await _client.PostAsync(uri, content);
Debug.WriteLine(content);
Debug.WriteLine(@"\tServiceInfo successfully sent.");
}
else
response = await _client.PutAsync(uri, content);
if (response.IsSuccessStatusCode)
Debug.WriteLine(@"\tServiceInfo successfully saved.");
}
catch (Exception ex)
{
Debug.WriteLine(@"\tERROR {0}", ex.Message);
}
}
< /code>
Я начинающий программист самоучки и не могу понять это. Чего мне не хватает!
Подробнее здесь: [url]https://stackoverflow.com/questions/79768717/why-is-insert-failing-in-net-web-api[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия