I have the LINQ query with the simple select statement which maps the columns from a table to the custom entity.
I have quite a few fields so I'm trying to select one by one and leave one field out. This way seems pretty silly to me. There was an option such as not select in SQL, it should have a counterpart in the entity framework.
I don't want to select the image area in this query. Do I have to write such a long code for this?
var result = from ch in _tenantDbContext.CariHesap
where ch.KartTipi == cariHesapKartTip
select new CariHesap
{
Id = ch.Id,
HesapKodu = ch.HesapKodu,
Unvan = ch.Unvan,
Ad = ch.Ad,
Soyad = ch.Soyad,
AktifPasif = ch.AktifPasif,
KartTipi = ch.KartTipi,
IslemTipi = ch.IslemTipi,
BakGostSekli = ch.BakGostSekli,
DvzTL = ch.DvzTL,
DovizCinsi = ch.DovizCinsi,
KrediLimiti = ch.KrediLimiti,
DvzKrediLimiti = ch.DvzKrediLimiti,
BolgeKod = ch.BolgeKod,
OzelKod = ch.OzelKod,
GrupKod = ch.GrupKod,
TipKod = ch.TipKod,
MhsKod = ch.MhsKod,
MasrafMerkezi = ch.MasrafMerkezi,
VergiDairesi = ch.VergiDairesi,
HesapNo = ch.HesapNo,
FaturaChk = ch.FaturaChk,
IskontoOran = ch.IskontoOran,
OpsiyonGunu = ch.OpsiyonGunu,
OdemeGunu = ch.OdemeGunu,
OdemePlani = ch.OdemePlani,
KulSatisFiyat = ch.KulSatisFiyat,
CHKodu = ch.CHKodu,
KDVTevfikatUygula = ch.KDVTevfikatUygula,
KDVMuaf = ch.KDVMuaf,
KDVMuafAck = ch.KDVMuafAck,
FormBaBsUnvan = ch.FormBaBsUnvan,
SirketEMail = ch.SirketEMail,
SirketWebAdres = ch.SirketWebAdres,
SatIslemEMail = ch.SatIslemEMail,
SatAlmaIslemEMail = ch.SatAlmaIslemEMail,
FinIslemEMail = ch.FinIslemEMail,
UnvanFaturadan = ch.UnvanFaturadan,
EFatSenaryo = ch.EFatSenaryo,
EIrsSenaryo = ch.EIrsSenaryo,
EMMSenaryo = ch.EMMSenaryo,
EFatEtiket = ch.EFatEtiket,
EIrsEtiket = ch.EIrsEtiket,
MusBrmSubeTanim = ch.MusBrmSubeTanim,
MusBrmSubeDeger = ch.MusBrmSubeDeger,
MusCHKoduTanim = ch.MusCHKoduTanim,
MusCHKoduDeger = ch.MusCHKoduDeger,
LegalEntityID = ch.LegalEntityID,
LegalEntityName = ch.LegalEntityName,
EArsivTeslimSekli = ch.EArsivTeslimSekli,
EArsivTeslimEMail1 = ch.EArsivTeslimEMail1,
EArsivTeslimEMail2 = ch.EArsivTeslimEMail2,
EArsivTeslimEMail3 = ch.EArsivTeslimEMail3,
FaturaXSLT = ch.FaturaXSLT,
IrsaliyeXSLT = ch.IrsaliyeXSLT,
SGKChk = ch.SGKChk,
SGKFaturaTipi = ch.SGKFaturaTipi,
KamuChk = ch.KamuChk,
Kod1 = ch.Kod1,
Kod2 = ch.Kod2,
Kod3 = ch.Kod3,
Kod4 = ch.Kod4,
Kod5 = ch.Kod5,
Kod6 = ch.Kod6,
Kod7 = ch.Kod7,
Kod8 = ch.Kod8,
Kod9 = ch.Kod9,
Kod10 = ch.Kod10,
Kod11 = ch.Kod11,
Kod12 = ch.Kod12,
Kod13 = ch.Kod13,
Kod14 = ch.Kod14,
Kod15 = ch.Kod15,
Nesne1 = ch.Nesne1,
Nesne2 = ch.Nesne2,
};
Related
I am consuming trade and quote data with BLPAPI in C#. When I process a LAST_TRADE_PRICE_TIME_TODAY_RT like this using //blp/mktdata service and processing the SUBCRIPTION_DATA event fine except for this message element:
{MarketDataEvents = {
RT_TIME_OF_TRADE = 2022-06-23
INDICATIVE_NEAR =
IMBALANCE_BUY =
IMBALANCE_SELL =
ORDER_IMB_BUY_VOLUME =
ORDER_IMB_SELL_VOLUME =
THEO_PRICE =
IMBALANCE_INDIC_RT =
PREV_CLOSE_VALUE_REALTIME = 11737.5
TRADING_DT_REALTIME = 2022-06-24
PREV_TRADING_DT_REALTIME = 2022-06-23
PX_ASK_LME_OFFICIAL_RT =
NUM_TRADES_RT = 0
PX_OFFICIAL_AUCTION_RT =
LAST_UPDATE_BID_RT = 2022-06-23
LAST_UPDATE_ASK_RT = 2022-06-23
OFFICIAL_AUCTION_VOLUME_RT =
IN_AUCTION_RT =
TURNOVER_TODAY_REALTIME =
OFFICIAL_OPEN_AUCTION_PRICE_RT =
OFFICIAL_OPEN_AUCTION_VOLUME_RT =
OFFICIAL_CLOSE_AUCTION_PRICE_RT =
OFFICIAL_CLOSE_AUCTION_VOLUME_RT =
AUCTION_EXTENSION_RT =
BLOCK_TRADE_ACCUM_VOLUME_RT =
TOTAL_MSG_SCRAPED_OFFERS_RT =
EVENT_TIME = 22:30:00.000
VOLUME_THEO =
OPEN_YLD_TDY_RT =
HIGH_YLD_TDY_RT =
LOW_YLD_TDY_RT =
LAST_YLD_TDY =
MID_TDY =
SIZE_LAST_TRADE_TDY =
RT_PX_CHG_NET_1D = 171.75
RT_PX_CHG_PCT_1D = 1.485
OPEN_TDY =
ASK_SIZE_TDY =
BID_SIZE_TDY =
VOLUME_TDY =
LAST_PRICE_TDY =
BID_TDY =
ASK_TDY =
HIGH_TDY =
LOW_TDY =
BID_YLD_TDY =
ASK_YLD_TDY =
TIME = 2022-06-23
LAST_UPDATE_ALL_SESSIONS_RT =
PX_OPEN_ALL_WITH_SWITCHOVER_RT =
BID_ALL_SESSION_TDY_RT =
ASK_ALL_SESSION_TDY_RT =
CONTINUOUS_TRAD_CLOS_BID_PX_RT =
CONTINUOUS_TRAD_CLOS_ASK_PX_RT =
POST_CLOSING_AUCTION_BID_PX_RT =
POST_CLOSING_AUCTION_ASK_PX_RT =
LAST_TRADE_RECEIVED_TIME_RT =
PRICE_CHANGE_ON_DAY_RT = 171.75
PRICE_LAST_ASK_RT =
PRICE_LAST_BID_RT =
PRICE_HIGH_RT =
PRICE_LOW_RT =
PRICE_OPEN_RT =
LAST_TRADE_PRICE_TODAY_RT =
PREVIOUS_TOTAL_VOLUME_RT = 622197
PREVIOUS_CLOSE_ADJ_BY_GR_DVD_RT =
TIME_AUCTION_CALL_CONCLUSION_RT =
PER_TRADE_VWAP_REALTIME =
PER_TRADE_VWAP_TURNOVER_RT =
PER_TRADE_VWAP_VOLUME_RT =
OPEN_HIGH_PRICE_REALTIME =
OPEN_LOW_PRICE_REALTIME =
CLOSE_HIGH_PRICE_REALTIME =
CLOSE_LOW_PRICE_REALTIME =
EXCHANGE_FOR_PHYSICAL_VOLUME_RT =
EXCHANGE_FOR_SWAP_VOLUME_RT =
LAST_BID_TIME_TODAY_REALTIME =
LAST_ASK_TIME_TODAY_REALTIME =
LAST_MID_TIME_TODAY_REALTIME =
LAST_PRICE_TIME_TODAY_REALTIME =
LAST_TRADE_PRICE_TIME_TODAY_RT =
MINIMUM_ORDER_LIMIT_PRICE_RT =
MAXIMUM_ORDER_LIMIT_PRICE_RT =
MIN_DYNAMIC_TRADING_LIMIT_PX_RT =
MAX_DYNAMIC_TRADING_LIMIT_PX_RT =
15_SECOND_PRICE_CHANGE_RT =
1_MINUTE_PRICE_CHANGE_RT =
5_MINUTE_PRICE_CHANGE_RT =
15_MINUTE_PRICE_CHANGE_RT =
1_HOUR_PRICE_CHANGE_RT =
CIRCUIT_BREAKER_TRIG_SIGNAL_RT =
LAST_CONTINUOUS_TRADE_PRICE_RT =
DYNAMIC_TRADING_LIMITS_REF_PX_RT =
LAST_OFF_BOOK_TRADE_PRICE_RT =
CB_TRIGGER_SIGNAL_START_TIME_RT =
CB_TRIGGER_SIGNAL_END_TIME_RT =
EFFECTIVE_DATE_RT =
OPEN_TRADE_PRICE_TODAY_RT =
HIGH_TRADE_PRICE_TODAY_RT =
LOW_TRADE_PRICE_TODAY_RT =
EXCHANGE_FOR_RISK_VOLUME_RT =
BLOOMBERG_CLOSE_PRICE_TODAY_RT =
PRICE_CLOSE_CC_TODAY_RT =
SUB_SEC_TM_AUCT_CALL_CNCLSN_RT =
THEORETICAL_TIME_TODAY_RT =
ON_EXCHANGE_VOLUME_TODAY_RT =
ON_BOOK_VOLUME_TODAY_RT =
LIT_BOOK_VOLUME_TODAY_RT =
CONTINUOUS_VOLUME_TODAY_RT =
AUCTION_VOLUME_TODAY_RT =
SCHEDULED_AUCT_VOLUME_TODAY_RT =
OPENING_AUCTION_VOLUME_RT =
CLOSING_AUCTION_VOLUME_RT =
INTRADAY_AUCTION_VOLUME_TODAY_RT =
UNSCHEDULED_AUCT_VOLUME_TODAY_RT =
TRADE_LAST_CLOSE_VOLUME_TODAY_RT =
PRE_POST_AUTO_EXECTN_VOL_TDY_RT =
DARK_BOOK_VOLUME_TODAY_RT =
ON_BK_NEG_BTF_OR_CC_VOL_TDY_RT =
ODD_LOT_BOOK_VOLUME_TODAY_RT =
OFF_BOOK_VOLUME_TODAY_RT =
NEGOTIATED_VOLUME_TODAY_RT =
OFF_BK_BLOCK_OR_CC_VOLUME_TDY_RT =
OFF_BOOK_ODD_LOT_VOLUME_TODAY_RT =
OTC_VOLUME_TODAY_RT =
SYSTEMATIC_INTERNAL_VOL_TDY_RT =
REPORTED_DARK_VOLUME_TODAY_RT =
PERCENT_CHANGE_ON_DAY_TODAY_RT =
NET_CHANGE_ON_DAY_TODAY_RT =
LAST_TRADE_AM_SESSION_TODAY_RT =
OPEN_PRICE_AM_SESSION_TODAY_RT =
HIGH_PRICE_AM_SESSION_TODAY_RT =
LOW_PRICE_AM_SESSION_TODAY_RT =
VOLUME_AM_SESSION_TODAY_RT =
LAST_TRADE_PM_SESSION_TODAY_RT =
OPEN_PRICE_PM_SESSION_TODAY_RT =
HIGH_PRICE_PM_SESSION_TODAY_RT =
LOW_PRICE_PM_SESSION_TODAY_RT =
VOLUME_PM_SESSION_TODAY_RT =
EXCHANGE_VWAP_TODAY_RT =
SETTLEMENT_PRESENT_VALUE_RT =
MATURITY_CALIBRATION_RATE_RT =
MATURITY_CALIBRATION_PV_RT =
CONTRIBUTED_RECOVERY_RATE_RT =
PAR_SPREAD_BID_RT =
PAR_SPREAD_ASK_RT =
LIQUIDITY_INDICATOR_RT =
PRICE_BID_CLOSE_TODAY_RT =
PRICE_ASK_CLOSE_TODAY_RT =
OFFICIAL_CLOSE_TODAY_RT =
PREVIOUS_BLOOMBERG_CLOSE_PX_RT = 11737.5
PREVIOUS_LAST_TRADE_PRICE_RT = 11688
BLOOMBERG_SEND_TIME_RT = 2022-06-23T21:31:23.469+00:00
10_MINUTE_PRICE_CHANGE_RT =
30_MINUTE_PRICE_CHANGE_RT =
BLOOMBERG_CLOSE_PX_AM_TODAY_RT =
PERIODIC_AUCT_ON_DMD_VOL_TDY_RT =
PERIODIC_AUCT_ON_DMD_THEO_PX_RT =
CHG_NET_REG_SES_PRV_RG_SES_CL_RT =
CHG_PCT_REG_SES_PRV_RG_SES_CL_RT =
ACTUAL_TRADED_PRICE_RT =
MIN_DYNMC_BID_ORDR_LIMT_PX_RT =
MAXMM_DYNMC_BID_ORDR_LIMT_PX_RT =
MIN_DYNMC_ASK_ORDR_LIMT_PX_RT =
MAXMM_DYNMC_ASK_ORDR_LIMT_PX_RT =
MKTDATA_EVENT_TYPE = SUMMARY
MKTDATA_EVENT_SUBTYPE = NEWDAY
DELTA_AVAT_30_DAY_INTERVAL =
DELTA_AVAT_1_DAY_INTERVAL =
DELTA_AVAT_5_DAY_INTERVAL =
DELTA_AVAT_10_DAY_INTERVAL =
DELTA_AVAT_20_DAY_INTERVAL =
DELTA_AVAT_100_DAY_INTERVAL =
DELTA_AVAT_180_DAY_INTERVAL =
DELTA_ATAT_1_DAY_INTERVAL =
DELTA_ATAT_5_DAY_INTERVAL =
DELTA_ATAT_10_DAY_INTERVAL =
DELTA_ATAT_20_DAY_INTERVAL =
DELTA_ATAT_30_DAY_INTERVAL =
DELTA_ATAT_100_DAY_INTERVAL =
DELTA_ATAT_180_DAY_INTERVAL =
REALTIME_15_SEC_PRICE_PCT_CHG =
REALTIME_ONE_MIN_PRICE_PCT_CHG =
REALTIME_FIVE_MIN_PRICE_PCT_CHG =
REALTIME_15_MIN_PRICE_PCT_CHG =
REALTIME_ONE_HOUR_PRICE_PCT_CHG =
REALTIME_VOLUME_5_DAY_INTERVAL =
CURRENT_SESSION_RT = 4
IMPLIED_BID_PRICE_RT =
IMPLIED_ASK_PRICE_RT =
IMPLIED_BID_SIZE_RT =
IMPLIED_ASK_SIZE_RT =
IS_DELAYED_STREAM = false
}
}
I use this to check the datetime and emit a trade event:
if (message.HasElement(LAST_TIME))
{
if (message.GetElementAsDatetime(LAST_TIME).IsValid())
{
DateTime time = message.GetElementAsDatetime(LAST_TIME).ToSystemDateTime();
if (message.HasElement(LAST) && message.HasElement(SIZE))
{
double last = message.GetElementAsFloat64(LAST);
int last_size = message.GetElementAsInt32(SIZE);
long volume = message.GetElementAsInt64(VOLUME); ...
I receive:
'Bloomberglp.Blpapi.NotFoundException: LAST_TRADE_PRICE_TIME_TODAY_RT has no value in MarketDataUpdate.'
I have tried converting to string first and checking if empty and checking null. Any ideas would be helpful...
I don't think checking the DataType is what you want. The
DataType is part of the schema. It should always be set even when there is no value. If it seems to be working, it is possibly because the element's data type is not DATETIME. For instance, if it is of type DATE, or TIME, GetAsDateTime would still work, but the DataType will never be DATETIME—meaning the code path will never get hit. What you want to check is if it has a value.
HasElement is saying that the schema contains such an element, but if the schema definition allows for there to be zero values (optional), it might not have a value. GetValueAsDatetime() is really GetValueAsDatetime(0), meaning the 0th value which may not exist. Note the same function can be used for array type items that have more than one value. I think the correct way to check this would be:
Element lastTime = message.GetElement(LAST_TIME);
if (lastTime.NumValues > 0) {
DateTime dt = lastTime.GetValueAsDatetime();
I suspect that
if (message.HasElement(LAST_TIME))
returns true because the field is there (but empty). However when you call:
if (message.GetElementAsDatetime(LAST_TIME).IsValid())
GetElementAsDatetime throws an exception because the value (which is empty) is not a valid datetime.
I think something like this may work:
Element lastTime = message.GetElement(LAST_TIME);
if (lastTime.Datatype() == Schema.Datatype.DATETIME) {
DateTime dt = lastTime.GetValueAsDatetime();
I want to get my linq query result back as json format. I have been searching for hours.
Here is my code :
public IEnumerable<callersW> GetAllCallersF()
{
testCDREntities1 context = this.CurrentDataSource;
var query = (
from oneCaller in CurrentDataSource.TestTables
select new
{
Created = oneCaller.Created,
Answered = oneCaller.Answered,
Destroyed = oneCaller.Destroyed,
CallerID = oneCaller.CallerId,
CalledID = oneCaller.CalledId,
DisconnectionCode = oneCaller.DisconnectionCode,
RTP_Caller_G107MOS = oneCaller.RTP_Caller_G107MOS,
RTP_Caller_LostPackets = oneCaller.RTP_Caller_LostPackets,
RTP_Caller_MaxRfc3550Jitter = oneCaller.RTP_Caller_MaxRfc3550Jitter,
RTP_Caller_MeanRfc3550Jitter = oneCaller.RTP_Caller_MeanRfc3550Jitter,
RTP_Called_G107MOS = oneCaller.RTP_Called_G107MOS,
RTP_Called_LostPackets = oneCaller.RTP_Called_LostPackets,
RTP_Called_MaxRfc3550Jitter = oneCaller.RTP_Called_MaxRfc3550Jitter,
RTP_Called_MeanRfc3550Jitter = oneCaller.RTP_Called_MeanRfc3550Jitter,
}).ToList()
.Select(x => new callersW
{
Created = Convert.ToDateTime(x.Created),
Answered = Convert.ToDateTime(x.Answered),
Destroyed = Convert.ToDateTime(x.Destroyed),
CallerID = x.CallerID,
CalledID = x.CalledID,
DisconnectionCode = Convert.ToInt32(x.DisconnectionCode),
RTP_Caller_G107MOS = Convert.ToDouble(x.RTP_Caller_G107MOS),
RTP_Caller_LostPackets = Convert.ToDouble(x.RTP_Caller_LostPackets),
RTP_Caller_MaxRfc3550Jitter = Convert.ToDouble(x.RTP_Caller_MaxRfc3550Jitter),
RTP_Caller_MeanRfc3550Jitter = Convert.ToDouble(x.RTP_Caller_MeanRfc3550Jitter),
RTP_Called_G107MOS = Convert.ToDouble(x.RTP_Called_G107MOS),
RTP_Called_LostPackets = Convert.ToDouble(x.RTP_Called_LostPackets),
RTP_Called_MaxRfc3550Jitter = Convert.ToDouble(x.RTP_Called_MaxRfc3550Jitter),
RTP_Called_MeanRfc3550Jitter = Convert.ToDouble(x.RTP_Called_MeanRfc3550Jitter)
}).ToList();
return query;
}
Can somebody help me with this ?
Add to your project JSON.NET and serialize object eg:
string json = JsonConvert.SerializeObject(query);
More examples here.
Is there a way on C# that I can convert unicode strings into ASCII + html entities, and then back again? See, in PHP, I can do it like so:
<?php
// RUN ME AT COMMAND LINE
$sUnicode = '<b>Jöhan Strauß</b>';
echo "UNICODE: $sUnicode\n";
$sASCII = mb_convert_encoding($sUnicode, 'HTML-ENTITIES','UTF-8');
echo "ASCII: $sASCII\n";
$sUnicode = mb_convert_encoding($sASCII, 'UTF-8', 'HTML-ENTITIES');
echo "UNICODE (TRANSLATED BACK): $sUnicode\n";
Background:
I need this to work in C# .NET 2 because we are constrained and can't use a higher .NET library in an older application.
I handle the PHP backend on this application. I wanted to share some tips with the C# frontend team on this project.
Yes, there's Encoding.Convert, although I rarely use it myself:
string text = "<b>Jöhan Strauß</b>";
byte[] ascii = Encoding.ASCII.GetBytes(text);
byte[] utf8 = Encoding.Convert(Encoding.ASCII, Encoding.UTF8, ascii);
I rarely find I want to convert from one encoded form to another - it's much more common to perform a one way conversion from text to binary (Encoding.GetBytes) or vice versa (Encoding.GetString).
HTML-ENTITIES isn't really a character encoding even though the PHP API might hint so. <b>Jöhan Strauß</b> is still UTF-8 encoded text (or even ASCII, ISO-8859-1, pretty much anything).
I couldn't find anything premade, except html encoding functions which are not the same thing at all since they encode &, < etc while mb_convert_encoding doesn't. I made t his class that should work:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class HtmlEntities
{
private static Dictionary<string, int> EntitiesToCodePoints;
private static Dictionary<int, string> CodePointsToEntities;
private static void Init()
{
if (EntitiesToCodePoints == null || CodePointsToEntities == null)
{
EntitiesToCodePoints = new Dictionary<string, int>();
CodePointsToEntities = new Dictionary<int, string>();
EntitiesToCodePoints["nbsp"] = 160; EntitiesToCodePoints["iexcl"] = 161; EntitiesToCodePoints["cent"] = 162; EntitiesToCodePoints["pound"] = 163; EntitiesToCodePoints["curren"] = 164; EntitiesToCodePoints["yen"] = 165; EntitiesToCodePoints["brvbar"] = 166; EntitiesToCodePoints["sect"] = 167; EntitiesToCodePoints["uml"] = 168; EntitiesToCodePoints["copy"] = 169; EntitiesToCodePoints["ordf"] = 170; EntitiesToCodePoints["laquo"] = 171; EntitiesToCodePoints["not"] = 172; EntitiesToCodePoints["shy"] = 173; EntitiesToCodePoints["reg"] = 174; EntitiesToCodePoints["macr"] = 175; EntitiesToCodePoints["deg"] = 176; EntitiesToCodePoints["plusmn"] = 177; EntitiesToCodePoints["sup2"] = 178; EntitiesToCodePoints["sup3"] = 179; EntitiesToCodePoints["acute"] = 180; EntitiesToCodePoints["micro"] = 181; EntitiesToCodePoints["para"] = 182; EntitiesToCodePoints["middot"] = 183; EntitiesToCodePoints["cedil"] = 184; EntitiesToCodePoints["sup1"] = 185; EntitiesToCodePoints["ordm"] = 186; EntitiesToCodePoints["raquo"] = 187; EntitiesToCodePoints["frac14"] = 188; EntitiesToCodePoints["frac12"] = 189; EntitiesToCodePoints["frac34"] = 190; EntitiesToCodePoints["iquest"] = 191; EntitiesToCodePoints["Agrave"] = 192; EntitiesToCodePoints["Aacute"] = 193; EntitiesToCodePoints["Acirc"] = 194; EntitiesToCodePoints["Atilde"] = 195; EntitiesToCodePoints["Auml"] = 196; EntitiesToCodePoints["Aring"] = 197; EntitiesToCodePoints["AElig"] = 198; EntitiesToCodePoints["Ccedil"] = 199; EntitiesToCodePoints["Egrave"] = 200; EntitiesToCodePoints["Eacute"] = 201; EntitiesToCodePoints["Ecirc"] = 202; EntitiesToCodePoints["Euml"] = 203; EntitiesToCodePoints["Igrave"] = 204; EntitiesToCodePoints["Iacute"] = 205; EntitiesToCodePoints["Icirc"] = 206; EntitiesToCodePoints["Iuml"] = 207; EntitiesToCodePoints["ETH"] = 208; EntitiesToCodePoints["Ntilde"] = 209; EntitiesToCodePoints["Ograve"] = 210; EntitiesToCodePoints["Oacute"] = 211; EntitiesToCodePoints["Ocirc"] = 212; EntitiesToCodePoints["Otilde"] = 213; EntitiesToCodePoints["Ouml"] = 214; EntitiesToCodePoints["times"] = 215; EntitiesToCodePoints["Oslash"] = 216; EntitiesToCodePoints["Ugrave"] = 217; EntitiesToCodePoints["Uacute"] = 218; EntitiesToCodePoints["Ucirc"] = 219; EntitiesToCodePoints["Uuml"] = 220; EntitiesToCodePoints["Yacute"] = 221; EntitiesToCodePoints["THORN"] = 222; EntitiesToCodePoints["szlig"] = 223; EntitiesToCodePoints["agrave"] = 224; EntitiesToCodePoints["aacute"] = 225; EntitiesToCodePoints["acirc"] = 226; EntitiesToCodePoints["atilde"] = 227; EntitiesToCodePoints["auml"] = 228; EntitiesToCodePoints["aring"] = 229; EntitiesToCodePoints["aelig"] = 230; EntitiesToCodePoints["ccedil"] = 231; EntitiesToCodePoints["egrave"] = 232; EntitiesToCodePoints["eacute"] = 233; EntitiesToCodePoints["ecirc"] = 234; EntitiesToCodePoints["euml"] = 235; EntitiesToCodePoints["igrave"] = 236; EntitiesToCodePoints["iacute"] = 237; EntitiesToCodePoints["icirc"] = 238; EntitiesToCodePoints["iuml"] = 239; EntitiesToCodePoints["eth"] = 240; EntitiesToCodePoints["ntilde"] = 241; EntitiesToCodePoints["ograve"] = 242; EntitiesToCodePoints["oacute"] = 243; EntitiesToCodePoints["ocirc"] = 244; EntitiesToCodePoints["otilde"] = 245; EntitiesToCodePoints["ouml"] = 246; EntitiesToCodePoints["divide"] = 247; EntitiesToCodePoints["oslash"] = 248; EntitiesToCodePoints["ugrave"] = 249; EntitiesToCodePoints["uacute"] = 250; EntitiesToCodePoints["ucirc"] = 251; EntitiesToCodePoints["uuml"] = 252; EntitiesToCodePoints["yacute"] = 253; EntitiesToCodePoints["thorn"] = 254; EntitiesToCodePoints["yuml"] = 255; EntitiesToCodePoints["OElig"] = 338; EntitiesToCodePoints["oelig"] = 339; EntitiesToCodePoints["Scaron"] = 352; EntitiesToCodePoints["scaron"] = 353; EntitiesToCodePoints["Yuml"] = 376; EntitiesToCodePoints["fnof"] = 402; EntitiesToCodePoints["circ"] = 710; EntitiesToCodePoints["tilde"] = 732; EntitiesToCodePoints["Alpha"] = 913; EntitiesToCodePoints["Beta"] = 914; EntitiesToCodePoints["Gamma"] = 915; EntitiesToCodePoints["Delta"] = 916; EntitiesToCodePoints["Epsilon"] = 917; EntitiesToCodePoints["Zeta"] = 918; EntitiesToCodePoints["Eta"] = 919; EntitiesToCodePoints["Theta"] = 920; EntitiesToCodePoints["Iota"] = 921; EntitiesToCodePoints["Kappa"] = 922; EntitiesToCodePoints["Lambda"] = 923; EntitiesToCodePoints["Mu"] = 924; EntitiesToCodePoints["Nu"] = 925; EntitiesToCodePoints["Xi"] = 926; EntitiesToCodePoints["Omicron"] = 927; EntitiesToCodePoints["Pi"] = 928; EntitiesToCodePoints["Rho"] = 929; EntitiesToCodePoints["Sigma"] = 931; EntitiesToCodePoints["Tau"] = 932; EntitiesToCodePoints["Upsilon"] = 933; EntitiesToCodePoints["Phi"] = 934; EntitiesToCodePoints["Chi"] = 935; EntitiesToCodePoints["Psi"] = 936; EntitiesToCodePoints["Omega"] = 937; EntitiesToCodePoints["alpha"] = 945; EntitiesToCodePoints["beta"] = 946; EntitiesToCodePoints["gamma"] = 947; EntitiesToCodePoints["delta"] = 948; EntitiesToCodePoints["epsilon"] = 949; EntitiesToCodePoints["zeta"] = 950; EntitiesToCodePoints["eta"] = 951; EntitiesToCodePoints["theta"] = 952; EntitiesToCodePoints["iota"] = 953; EntitiesToCodePoints["kappa"] = 954; EntitiesToCodePoints["lambda"] = 955; EntitiesToCodePoints["mu"] = 956; EntitiesToCodePoints["nu"] = 957; EntitiesToCodePoints["xi"] = 958; EntitiesToCodePoints["omicron"] = 959; EntitiesToCodePoints["pi"] = 960; EntitiesToCodePoints["rho"] = 961; EntitiesToCodePoints["sigmaf"] = 962; EntitiesToCodePoints["sigma"] = 963; EntitiesToCodePoints["tau"] = 964; EntitiesToCodePoints["upsilon"] = 965; EntitiesToCodePoints["phi"] = 966; EntitiesToCodePoints["chi"] = 967; EntitiesToCodePoints["psi"] = 968; EntitiesToCodePoints["omega"] = 969; EntitiesToCodePoints["thetasym"] = 977; EntitiesToCodePoints["upsih"] = 978; EntitiesToCodePoints["piv"] = 982; EntitiesToCodePoints["ensp"] = 8194; EntitiesToCodePoints["emsp"] = 8195; EntitiesToCodePoints["thinsp"] = 8201; EntitiesToCodePoints["zwnj"] = 8204; EntitiesToCodePoints["zwj"] = 8205; EntitiesToCodePoints["lrm"] = 8206; EntitiesToCodePoints["rlm"] = 8207; EntitiesToCodePoints["ndash"] = 8211; EntitiesToCodePoints["mdash"] = 8212; EntitiesToCodePoints["lsquo"] = 8216; EntitiesToCodePoints["rsquo"] = 8217; EntitiesToCodePoints["sbquo"] = 8218; EntitiesToCodePoints["ldquo"] = 8220; EntitiesToCodePoints["rdquo"] = 8221; EntitiesToCodePoints["bdquo"] = 8222; EntitiesToCodePoints["dagger"] = 8224; EntitiesToCodePoints["Dagger"] = 8225; EntitiesToCodePoints["bull"] = 8226; EntitiesToCodePoints["hellip"] = 8230; EntitiesToCodePoints["permil"] = 8240; EntitiesToCodePoints["prime"] = 8242; EntitiesToCodePoints["Prime"] = 8243; EntitiesToCodePoints["lsaquo"] = 8249; EntitiesToCodePoints["rsaquo"] = 8250; EntitiesToCodePoints["oline"] = 8254; EntitiesToCodePoints["frasl"] = 8260; EntitiesToCodePoints["euro"] = 8364; EntitiesToCodePoints["weierp"] = 8472; EntitiesToCodePoints["image"] = 8465; EntitiesToCodePoints["real"] = 8476; EntitiesToCodePoints["trade"] = 8482; EntitiesToCodePoints["alefsym"] = 8501; EntitiesToCodePoints["larr"] = 8592; EntitiesToCodePoints["uarr"] = 8593; EntitiesToCodePoints["rarr"] = 8594; EntitiesToCodePoints["darr"] = 8595; EntitiesToCodePoints["harr"] = 8596; EntitiesToCodePoints["crarr"] = 8629; EntitiesToCodePoints["lArr"] = 8656; EntitiesToCodePoints["uArr"] = 8657; EntitiesToCodePoints["rArr"] = 8658; EntitiesToCodePoints["dArr"] = 8659; EntitiesToCodePoints["hArr"] = 8660; EntitiesToCodePoints["forall"] = 8704; EntitiesToCodePoints["part"] = 8706; EntitiesToCodePoints["exist"] = 8707; EntitiesToCodePoints["empty"] = 8709; EntitiesToCodePoints["nabla"] = 8711; EntitiesToCodePoints["isin"] = 8712; EntitiesToCodePoints["notin"] = 8713; EntitiesToCodePoints["ni"] = 8715; EntitiesToCodePoints["prod"] = 8719; EntitiesToCodePoints["sum"] = 8721; EntitiesToCodePoints["minus"] = 8722; EntitiesToCodePoints["lowast"] = 8727; EntitiesToCodePoints["radic"] = 8730; EntitiesToCodePoints["prop"] = 8733; EntitiesToCodePoints["infin"] = 8734; EntitiesToCodePoints["ang"] = 8736; EntitiesToCodePoints["and"] = 8743; EntitiesToCodePoints["or"] = 8744; EntitiesToCodePoints["cap"] = 8745; EntitiesToCodePoints["cup"] = 8746; EntitiesToCodePoints["int"] = 8747; EntitiesToCodePoints["there4"] = 8756; EntitiesToCodePoints["sim"] = 8764; EntitiesToCodePoints["cong"] = 8773; EntitiesToCodePoints["asymp"] = 8776; EntitiesToCodePoints["ne"] = 8800; EntitiesToCodePoints["equiv"] = 8801; EntitiesToCodePoints["le"] = 8804; EntitiesToCodePoints["ge"] = 8805; EntitiesToCodePoints["sub"] = 8834; EntitiesToCodePoints["sup"] = 8835; EntitiesToCodePoints["nsub"] = 8836; EntitiesToCodePoints["sube"] = 8838; EntitiesToCodePoints["supe"] = 8839; EntitiesToCodePoints["oplus"] = 8853; EntitiesToCodePoints["otimes"] = 8855; EntitiesToCodePoints["perp"] = 8869; EntitiesToCodePoints["sdot"] = 8901; EntitiesToCodePoints["lceil"] = 8968; EntitiesToCodePoints["rceil"] = 8969; EntitiesToCodePoints["lfloor"] = 8970; EntitiesToCodePoints["rfloor"] = 8971; EntitiesToCodePoints["lang"] = 9001; EntitiesToCodePoints["rang"] = 9002; EntitiesToCodePoints["loz"] = 9674; EntitiesToCodePoints["spades"] = 9824; EntitiesToCodePoints["clubs"] = 9827; EntitiesToCodePoints["hearts"] = 9829; EntitiesToCodePoints["diams"] = 9830;
CodePointsToEntities[160] = "nbsp"; CodePointsToEntities[161] = "iexcl"; CodePointsToEntities[162] = "cent"; CodePointsToEntities[163] = "pound"; CodePointsToEntities[164] = "curren"; CodePointsToEntities[165] = "yen"; CodePointsToEntities[166] = "brvbar"; CodePointsToEntities[167] = "sect"; CodePointsToEntities[168] = "uml"; CodePointsToEntities[169] = "copy"; CodePointsToEntities[170] = "ordf"; CodePointsToEntities[171] = "laquo"; CodePointsToEntities[172] = "not"; CodePointsToEntities[173] = "shy"; CodePointsToEntities[174] = "reg"; CodePointsToEntities[175] = "macr"; CodePointsToEntities[176] = "deg"; CodePointsToEntities[177] = "plusmn"; CodePointsToEntities[178] = "sup2"; CodePointsToEntities[179] = "sup3"; CodePointsToEntities[180] = "acute"; CodePointsToEntities[181] = "micro"; CodePointsToEntities[182] = "para"; CodePointsToEntities[183] = "middot"; CodePointsToEntities[184] = "cedil"; CodePointsToEntities[185] = "sup1"; CodePointsToEntities[186] = "ordm"; CodePointsToEntities[187] = "raquo"; CodePointsToEntities[188] = "frac14"; CodePointsToEntities[189] = "frac12"; CodePointsToEntities[190] = "frac34"; CodePointsToEntities[191] = "iquest"; CodePointsToEntities[192] = "Agrave"; CodePointsToEntities[193] = "Aacute"; CodePointsToEntities[194] = "Acirc"; CodePointsToEntities[195] = "Atilde"; CodePointsToEntities[196] = "Auml"; CodePointsToEntities[197] = "Aring"; CodePointsToEntities[198] = "AElig"; CodePointsToEntities[199] = "Ccedil"; CodePointsToEntities[200] = "Egrave"; CodePointsToEntities[201] = "Eacute"; CodePointsToEntities[202] = "Ecirc"; CodePointsToEntities[203] = "Euml"; CodePointsToEntities[204] = "Igrave"; CodePointsToEntities[205] = "Iacute"; CodePointsToEntities[206] = "Icirc"; CodePointsToEntities[207] = "Iuml"; CodePointsToEntities[208] = "ETH"; CodePointsToEntities[209] = "Ntilde"; CodePointsToEntities[210] = "Ograve"; CodePointsToEntities[211] = "Oacute"; CodePointsToEntities[212] = "Ocirc"; CodePointsToEntities[213] = "Otilde"; CodePointsToEntities[214] = "Ouml"; CodePointsToEntities[215] = "times"; CodePointsToEntities[216] = "Oslash"; CodePointsToEntities[217] = "Ugrave"; CodePointsToEntities[218] = "Uacute"; CodePointsToEntities[219] = "Ucirc"; CodePointsToEntities[220] = "Uuml"; CodePointsToEntities[221] = "Yacute"; CodePointsToEntities[222] = "THORN"; CodePointsToEntities[223] = "szlig"; CodePointsToEntities[224] = "agrave"; CodePointsToEntities[225] = "aacute"; CodePointsToEntities[226] = "acirc"; CodePointsToEntities[227] = "atilde"; CodePointsToEntities[228] = "auml"; CodePointsToEntities[229] = "aring"; CodePointsToEntities[230] = "aelig"; CodePointsToEntities[231] = "ccedil"; CodePointsToEntities[232] = "egrave"; CodePointsToEntities[233] = "eacute"; CodePointsToEntities[234] = "ecirc"; CodePointsToEntities[235] = "euml"; CodePointsToEntities[236] = "igrave"; CodePointsToEntities[237] = "iacute"; CodePointsToEntities[238] = "icirc"; CodePointsToEntities[239] = "iuml"; CodePointsToEntities[240] = "eth"; CodePointsToEntities[241] = "ntilde"; CodePointsToEntities[242] = "ograve"; CodePointsToEntities[243] = "oacute"; CodePointsToEntities[244] = "ocirc"; CodePointsToEntities[245] = "otilde"; CodePointsToEntities[246] = "ouml"; CodePointsToEntities[247] = "divide"; CodePointsToEntities[248] = "oslash"; CodePointsToEntities[249] = "ugrave"; CodePointsToEntities[250] = "uacute"; CodePointsToEntities[251] = "ucirc"; CodePointsToEntities[252] = "uuml"; CodePointsToEntities[253] = "yacute"; CodePointsToEntities[254] = "thorn"; CodePointsToEntities[255] = "yuml"; CodePointsToEntities[338] = "OElig"; CodePointsToEntities[339] = "oelig"; CodePointsToEntities[352] = "Scaron"; CodePointsToEntities[353] = "scaron"; CodePointsToEntities[376] = "Yuml"; CodePointsToEntities[402] = "fnof"; CodePointsToEntities[710] = "circ"; CodePointsToEntities[732] = "tilde"; CodePointsToEntities[913] = "Alpha"; CodePointsToEntities[914] = "Beta"; CodePointsToEntities[915] = "Gamma"; CodePointsToEntities[916] = "Delta"; CodePointsToEntities[917] = "Epsilon"; CodePointsToEntities[918] = "Zeta"; CodePointsToEntities[919] = "Eta"; CodePointsToEntities[920] = "Theta"; CodePointsToEntities[921] = "Iota"; CodePointsToEntities[922] = "Kappa"; CodePointsToEntities[923] = "Lambda"; CodePointsToEntities[924] = "Mu"; CodePointsToEntities[925] = "Nu"; CodePointsToEntities[926] = "Xi"; CodePointsToEntities[927] = "Omicron"; CodePointsToEntities[928] = "Pi"; CodePointsToEntities[929] = "Rho"; CodePointsToEntities[931] = "Sigma"; CodePointsToEntities[932] = "Tau"; CodePointsToEntities[933] = "Upsilon"; CodePointsToEntities[934] = "Phi"; CodePointsToEntities[935] = "Chi"; CodePointsToEntities[936] = "Psi"; CodePointsToEntities[937] = "Omega"; CodePointsToEntities[945] = "alpha"; CodePointsToEntities[946] = "beta"; CodePointsToEntities[947] = "gamma"; CodePointsToEntities[948] = "delta"; CodePointsToEntities[949] = "epsilon"; CodePointsToEntities[950] = "zeta"; CodePointsToEntities[951] = "eta"; CodePointsToEntities[952] = "theta"; CodePointsToEntities[953] = "iota"; CodePointsToEntities[954] = "kappa"; CodePointsToEntities[955] = "lambda"; CodePointsToEntities[956] = "mu"; CodePointsToEntities[957] = "nu"; CodePointsToEntities[958] = "xi"; CodePointsToEntities[959] = "omicron"; CodePointsToEntities[960] = "pi"; CodePointsToEntities[961] = "rho"; CodePointsToEntities[962] = "sigmaf"; CodePointsToEntities[963] = "sigma"; CodePointsToEntities[964] = "tau"; CodePointsToEntities[965] = "upsilon"; CodePointsToEntities[966] = "phi"; CodePointsToEntities[967] = "chi"; CodePointsToEntities[968] = "psi"; CodePointsToEntities[969] = "omega"; CodePointsToEntities[977] = "thetasym"; CodePointsToEntities[978] = "upsih"; CodePointsToEntities[982] = "piv"; CodePointsToEntities[8194] = "ensp"; CodePointsToEntities[8195] = "emsp"; CodePointsToEntities[8201] = "thinsp"; CodePointsToEntities[8204] = "zwnj"; CodePointsToEntities[8205] = "zwj"; CodePointsToEntities[8206] = "lrm"; CodePointsToEntities[8207] = "rlm"; CodePointsToEntities[8211] = "ndash"; CodePointsToEntities[8212] = "mdash"; CodePointsToEntities[8216] = "lsquo"; CodePointsToEntities[8217] = "rsquo"; CodePointsToEntities[8218] = "sbquo"; CodePointsToEntities[8220] = "ldquo"; CodePointsToEntities[8221] = "rdquo"; CodePointsToEntities[8222] = "bdquo"; CodePointsToEntities[8224] = "dagger"; CodePointsToEntities[8225] = "Dagger"; CodePointsToEntities[8226] = "bull"; CodePointsToEntities[8230] = "hellip"; CodePointsToEntities[8240] = "permil"; CodePointsToEntities[8242] = "prime"; CodePointsToEntities[8243] = "Prime"; CodePointsToEntities[8249] = "lsaquo"; CodePointsToEntities[8250] = "rsaquo"; CodePointsToEntities[8254] = "oline"; CodePointsToEntities[8260] = "frasl"; CodePointsToEntities[8364] = "euro"; CodePointsToEntities[8472] = "weierp"; CodePointsToEntities[8465] = "image"; CodePointsToEntities[8476] = "real"; CodePointsToEntities[8482] = "trade"; CodePointsToEntities[8501] = "alefsym"; CodePointsToEntities[8592] = "larr"; CodePointsToEntities[8593] = "uarr"; CodePointsToEntities[8594] = "rarr"; CodePointsToEntities[8595] = "darr"; CodePointsToEntities[8596] = "harr"; CodePointsToEntities[8629] = "crarr"; CodePointsToEntities[8656] = "lArr"; CodePointsToEntities[8657] = "uArr"; CodePointsToEntities[8658] = "rArr"; CodePointsToEntities[8659] = "dArr"; CodePointsToEntities[8660] = "hArr"; CodePointsToEntities[8704] = "forall"; CodePointsToEntities[8706] = "part"; CodePointsToEntities[8707] = "exist"; CodePointsToEntities[8709] = "empty"; CodePointsToEntities[8711] = "nabla"; CodePointsToEntities[8712] = "isin"; CodePointsToEntities[8713] = "notin"; CodePointsToEntities[8715] = "ni"; CodePointsToEntities[8719] = "prod"; CodePointsToEntities[8721] = "sum"; CodePointsToEntities[8722] = "minus"; CodePointsToEntities[8727] = "lowast"; CodePointsToEntities[8730] = "radic"; CodePointsToEntities[8733] = "prop"; CodePointsToEntities[8734] = "infin"; CodePointsToEntities[8736] = "ang"; CodePointsToEntities[8743] = "and"; CodePointsToEntities[8744] = "or"; CodePointsToEntities[8745] = "cap"; CodePointsToEntities[8746] = "cup"; CodePointsToEntities[8747] = "int"; CodePointsToEntities[8756] = "there4"; CodePointsToEntities[8764] = "sim"; CodePointsToEntities[8773] = "cong"; CodePointsToEntities[8776] = "asymp"; CodePointsToEntities[8800] = "ne"; CodePointsToEntities[8801] = "equiv"; CodePointsToEntities[8804] = "le"; CodePointsToEntities[8805] = "ge"; CodePointsToEntities[8834] = "sub"; CodePointsToEntities[8835] = "sup"; CodePointsToEntities[8836] = "nsub"; CodePointsToEntities[8838] = "sube"; CodePointsToEntities[8839] = "supe"; CodePointsToEntities[8853] = "oplus"; CodePointsToEntities[8855] = "otimes"; CodePointsToEntities[8869] = "perp"; CodePointsToEntities[8901] = "sdot"; CodePointsToEntities[8968] = "lceil"; CodePointsToEntities[8969] = "rceil"; CodePointsToEntities[8970] = "lfloor"; CodePointsToEntities[8971] = "rfloor"; CodePointsToEntities[9001] = "lang"; CodePointsToEntities[9002] = "rang"; CodePointsToEntities[9674] = "loz"; CodePointsToEntities[9824] = "spades"; CodePointsToEntities[9827] = "clubs"; CodePointsToEntities[9829] = "hearts"; CodePointsToEntities[9830] = "diams";
}
}
public static string Decode(string str)
{
Init();
return Regex.Replace(str, #"&(?:#(?<num>[0-9]+)|(?<named>[0-9A-Za-z]+));", delegate(Match m)
{
int charCode;
string captured;
if (m.Groups["num"].Captures.Count > 0)
{
if (!int.TryParse(m.Groups["num"].ToString(), out charCode))
{//Return unaffected
return m.Groups[0].ToString();
}
}
else
{
captured = m.Groups["named"].ToString();
if( EntitiesToCodePoints.ContainsKey(captured) ) {
charCode = EntitiesToCodePoints[captured];
}
else {
//Return unaffected
return m.Groups[0].ToString();
}
}
return Convert.ToChar(charCode).ToString();
});
}
public static string Encode(string str)
{
Init();
return Regex.Replace(str, #"[\u0080-\uDAFF\uE000-\uFFFF]", delegate(Match m)
{
int codePoint = (int)m.Value[0];
if (CodePointsToEntities.ContainsKey(codePoint))
{
return "&" + CodePointsToEntities[codePoint] + ";";
}
return "&#" + codePoint + ";";
});
}
}
}
PHP:
$a = "ɢ♠♤ä<>&'\"";
$b = mb_convert_encoding( $a, "HTML-ENTITIES", "UTF-8" );
echo $b; //ɢ♠♤ä<>&'"
echo mb_convert_encoding( $b, "UTF-8", "HTML-ENTITIES"); //ɢ♠♤ä<>&'"
C#
string a = "ɢ♠♤ä<>&'\"";
string b = HtmlEntities.Encode(a);
Console.WriteLine(b); //ɢ♠♤ä<>&'"
Console.WriteLine(HtmlEntities.Decode(b)); //ɢ♠♤ä<>&'"
Note: This cannot handle characters outside BMP, though such a requirement is so rare that it should be explicitly mentioned.
Here are some examples of conversions. The first two show how to convert, the last one can be turned into a function that takes two encoding names as strings, and convert.
A list of encoding names can be found here.
Encoding.UTF8.GetString(Encoding.ASCII.GetBytes(str));
Encoding.UTF8.GetString(Encoding.Unicode.GetBytes(str));
Encoding.GetEncoding("UTF-8").GetString(Encoding.GetEncoding("ASCII").GetBytes(str));
I have some code that is using the following xml file. Can someone tell me why my doc.Descendants is returning null?
Here is the XML File:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<EmployerTPASeparationResponseCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://uidataexchange.org/schemas SeparationResponse.xsd" xmlns="https://uidataexchange.org/schemas">
<EmployerTPASeparationResponse>
<StateRequestRecordGUID>94321098761987654321323456109883</StateRequestRecordGUID>
<BrokerRecordTransactionNumber>123456789</BrokerRecordTransactionNumber>
<SSN>999999999</SSN>
<ClaimEffectiveDate>2011-02-09</ClaimEffectiveDate>
<ClaimNumber>1234568010</ClaimNumber>
<StateEmployerAccountNbr>12345689</StateEmployerAccountNbr>
<ClaimantJobTitle>Assistant Manager</ClaimantJobTitle>
<EmployerReportedClaimantFirstDayofWork>2009-02-02</EmployerReportedClaimantFirstDayofWork>
<EmployerReportedClaimantLastDayofWork>2010-03-16</EmployerReportedClaimantLastDayofWork>
<TotalEarnedWagesNeededInd>2</TotalEarnedWagesNeededInd>
<TotalEarnedWages>15000.00</TotalEarnedWages>
<WagesEarnedAfterClaimEffectiveDate>20000.00</WagesEarnedAfterClaimEffectiveDate>
<NumberOfHoursWorkedAfterClaimEffectiveDate>80</NumberOfHoursWorkedAfterClaimEffectiveDate>
<AverageWeeklyWage>10.00</AverageWeeklyWage>
<EmployerSepReasonCode>2</EmployerSepReasonCode>
<EmployerSepReasonComments>Expected return date back to work is 4/25/11</EmployerSepReasonComments>
<PreparerTypeCode>T</PreparerTypeCode>
<PreparerCompanyName>Barnett Associates</PreparerCompanyName>
<PreparerTelephoneNumberPlusExt>5555555555</PreparerTelephoneNumberPlusExt>
<PreparerContactName>Diana Turkoane</PreparerContactName>
<PreparerTitle>CSR</PreparerTitle>
<PreparerFaxNbr>5555555555</PreparerFaxNbr>
<PreparerEmailAddress>asdf#asdf.com</PreparerEmailAddress>
</EmployerTPASeparationResponse>
<EmployerTPASeparationResponse>
<StateRequestRecordGUID>94321098761987654321323456109884</StateRequestRecordGUID>
<BrokerRecordTransactionNumber>123456789</BrokerRecordTransactionNumber>
<SSN>999999999</SSN>
<ClaimEffectiveDate>2011-02-10</ClaimEffectiveDate>
<ClaimNumber>1234568010</ClaimNumber>
<StateEmployerAccountNbr>12345689</StateEmployerAccountNbr>
<ClaimantJobTitle>Assistant Manager</ClaimantJobTitle>
<EmployerReportedClaimantFirstDayofWork>2009-02-03</EmployerReportedClaimantFirstDayofWork>
<EmployerReportedClaimantLastDayofWork>2010-03-17</EmployerReportedClaimantLastDayofWork>
<EmployerSepReasonCode>2</EmployerSepReasonCode>
<EmployerSepReasonComments>Expected return date back to work is 4/30/11</EmployerSepReasonComments>
<PreparerTypeCode>T</PreparerTypeCode>
<PreparerCompanyName>Barnett Associates</PreparerCompanyName>
<PreparerTelephoneNumberPlusExt>5555555555</PreparerTelephoneNumberPlusExt>
<PreparerContactName>Diana Turkoane</PreparerContactName>
<PreparerTitle>CSR</PreparerTitle>
<PreparerFaxNbr>5555555555</PreparerFaxNbr>
<PreparerEmailAddress>asdf#asdf.com</PreparerEmailAddress>
</EmployerTPASeparationResponse>
</EmployerTPASeparationResponseCollection>
Here is the code I am using. I first use some Linq to get the Anonymous values, then try to loop through each child node and populate with cmd.parameters.
Here is the code:
XDocument doc = XDocument.Load("XmlString.xml");
var EmployerTPASeparationResponse =
from node in doc.Descendants("EmployerTPASeparationResponse")
select new
{
param1 = node.Element("StateRequestRecordGUID").Value,
param2 = node.Element("BrokerRecordTransactionNumber").Value,
param3 = node.Element("SSN").Value,
param4 = node.Element("ClaimEffectiveDate").Value,
param5 = node.Element("ClaimNumber").Value,
param6 = node.Element("StateEmployerAccountNbr").Value,
param7 = node.Element("CorrectedEmployerName").Value,
param8 = node.Element("CorrectedStateEmployerAccountNbr").Value,
param9 = node.Element("CorrectedFEIN").Value,
param10 = node.Element("OtherSSN").Value,
param11 = node.Element("ClaimantNameWorkedAsForEmployers").Value,
param12 = node.Element("ClaimantJobTitle").Value,
param13 = node.Element("SeasonalEmploymentInd").Value,
param14 = node.Element("EmployerReportedClaimantFirstDayofWork").Value,
param15 = node.Element("EmployerReportedClaimantLastDayofWork").Value,
param16 = node.Element("EffectiveSeparationDate").Value,
param17 = node.Element("TotalEarnedWagesNeededInd").Value,
param18 = node.Element("TotalEarnedWages").Value,
param19 = node.Element("TotalWeeksWorkedNeededInd").Value,
param20 = node.Element("TotalWeeksWorked").Value,
param21 = node.Element("WagesEarnedAfterClaimEffectiveDate").Value,
param22 = node.Element("NumberOfHoursWorkedAfterClaimEffectiveDate").Value,
param23 = node.Element("AverageWeeklyWage").Value,
param24 = node.Element("EmployerSepReasonCode").Value,
param25 = node.Element("ReturnToWorkInd").Value,
param26 = node.Element("ReturnToWorkDate").Value,
param27 = node.Element("WorkingAllAvailableHoursInd").Value,
param28 = node.Element("NotWorkingAvailableHoursReason").Value,
param29 = node.Element("DischargeReasonCode").Value,
param30 = node.Element("FinalIncidentReason").Value,
param31 = node.Element("FinalIncidentDate").Value,
param32 = node.Element("ViolateCompanyPolicyInd").Value,
param33 = node.Element("DischargePolicyAwareInd").Value,
param34 = node.Element("DischargePolicyAwareExplanationCode").Value,
param35 = node.Element("WhoDischargedName").Value,
param36 = node.Element("WhoDischargedTitle").Value,
param37 = node.Element("DischargeReasonComments").Value,
param38 = node.Element("VoluntarySepReasonCode").Value,
param39 = node.Element("HiringAgreementChangesCode").Value,
param40 = node.Element("HiringAgreementChangeComments").Value,
param41 = node.Element("ClaimantActionstoAvoidQuitInd").Value,
param42 = node.Element("ActionTakenComments").Value,
param43 = node.Element("ContinuingWorkAvailableInd").Value,
param44 = node.Element("VoluntarySepReasonComments").Value,
param45 = node.Element("AmendedResponse").Value,
param46 = node.Element("AmendedResponseDescription").Value,
param47 = node.Element("EmployerSepReasonComments").Value,
param48 = node.Element("LaborDisputeTypeInd").Value,
param49 = node.Element("AttachmentID").Value,
param50 = node.Element("MandatoryRetirementInd").Value,
param51 = node.Element("PriorIncidentID").Value,
param52 = node.Element("PreparerTypeCode").Value,
param53 = node.Element("PreparerCompanyName").Value,
param54 = node.Element("PreparerTelephoneNumberPlusExt").Value,
param55 = node.Element("PreparerContactName").Value,
param56 = node.Element("PreparerTitle").Value,
param57 = node.Element("PreparerFaxNbr").Value,
param58 = node.Element("PreparerEmailAddress").Value,
};
foreach (var node in EmployerTPASeparationResponse)
{
cmd4.Parameters["StateRequestRecordGUID"].Value = node.param1;
cmd4.Parameters["BrokerRecordTransactionNumber"].Value = node.param2;
cmd4.Parameters["SSN"].Value = node.param3;
cmd4.Parameters["ClaimEffectiveDate"].Value = node.param4;
cmd4.Parameters["ClaimNumber"].Value = node.param5;
cmd4.Parameters["StateEmployerAccountNbr"].Value = node.param6;
cmd4.Parameters["CorrectedEmployerName"].Value = node.param7;
cmd4.Parameters["CorrectedStateEmployerAccountNbr"].Value = node.param8;
cmd4.Parameters["CorrectedFEIN"].Value = node.param9;
cmd4.Parameters["OtherSSN"].Value = node.param10;
cmd4.Parameters["ClaimantNameWorkedAsForEmployers"].Value = node.param11;
cmd4.Parameters["ClaimantJobTitle"].Value = node.param12;
cmd4.Parameters["SeasonalEmploymentInd"].Value = node.param13;
cmd4.Parameters["EmployerReportedClaimantFirstDayofWork"].Value = node.param14;
cmd4.Parameters["EmployerReportedClaimantLastDayofWork"].Value = node.param15;
cmd4.Parameters["EffectiveSeparationDate"].Value = node.param16;
cmd4.Parameters["TotalEarnedWagesNeededInd"].Value = node.param17;
cmd4.Parameters["TotalEarnedWages"].Value = node.param18;
cmd4.Parameters["TotalWeeksWorkedNeededInd"].Value = node.param19;
cmd4.Parameters["TotalWeeksWorked"].Value = node.param20;
cmd4.Parameters["WagesEarnedAfterClaimEffectiveDate"].Value = node.param21;
cmd4.Parameters["NumberOfHoursWorkedAfterClaimEffectiveDate"].Value = node.param22;
cmd4.Parameters["AverageWeeklyWage"].Value = node.param23;
cmd4.Parameters["EmployerSepReasonCode"].Value = node.param24;
cmd4.Parameters["ReturnToWorkInd"].Value = node.param25;
cmd4.Parameters["ReturnToWorkDate"].Value = node.param26;
cmd4.Parameters["WorkingAllAvailableHoursInd"].Value = node.param27;
cmd4.Parameters["NotWorkingAvailableHoursReason"].Value = node.param28;
cmd4.Parameters["DischargeReasonCode"].Value = node.param29;
cmd4.Parameters["FinalIncidentReason"].Value = node.param30;
cmd4.Parameters["FinalIncidentDate"].Value = node.param31;
cmd4.Parameters["ViolateCompanyPolicyInd"].Value = node.param32;
cmd4.Parameters["DischargePolicyAwareInd"].Value = node.param33;
cmd4.Parameters["DischargePolicyAwareExplanationCode"].Value = node.param34;
cmd4.Parameters["WhoDischargedName"].Value = node.param35;
cmd4.Parameters["WhoDischargedTitle"].Value = node.param36;
cmd4.Parameters["DischargeReasonComments"].Value = node.param37;
cmd4.Parameters["VoluntarySepReasonCode"].Value = node.param38;
cmd4.Parameters["HiringAgreementChangesCode"].Value = node.param39;
cmd4.Parameters["HiringAgreementChangeComments"].Value = node.param40;
cmd4.Parameters["ClaimantActionstoAvoidQuitInd"].Value = node.param41;
cmd4.Parameters["ActionTakenComments"].Value = node.param42;
cmd4.Parameters["ContinuingWorkAvailableInd"].Value = node.param43;
cmd4.Parameters["VoluntarySepReasonComments"].Value = node.param44;
cmd4.Parameters["AmendedResponse"].Value = node.param45;
cmd4.Parameters["AmendedResponseDescription"].Value = node.param46;
cmd4.Parameters["EmployerSepReasonComments"].Value = node.param47;
cmd4.Parameters["LaborDisputeTypeInd"].Value = node.param48;
cmd4.Parameters["AttachmentID"].Value = node.param49;
cmd4.Parameters["MandatoryRetirementInd"].Value = node.param50;
cmd4.Parameters["PriorIncidentID"].Value = node.param51;
cmd4.Parameters["PreparerTypeCode"].Value = node.param52;
cmd4.Parameters["PreparerCompanyName"].Value = node.param53;
cmd4.Parameters["PreparerTelephoneNumberPlusExt"].Value = node.param54;
cmd4.Parameters["PreparerContactName"].Value = node.param55;
cmd4.Parameters["PreparerTitle"].Value = node.param56;
cmd4.Parameters["PreparerFaxNbr"].Value = node.param57;
cmd4.Parameters["PreparerEmailAddress"].Value = node.param58;
cmd4.ExecuteNonQuery();
if (cmd4 != null)
{
cmd4 = null;
}
}
You need to include the namespace (xmlns) in all of the element names:
XNamespace ns = "https://uidataexchange.org/schemas";
doc.Descendants(ns + "EmployerTPASeparationResponse")
(And in all of the Element calls)
Note that your code can be made dramatically shorter by looping through the child elements and adding parameters with their names instead of using anonymous types.
For example:
var node = doc.Descendants(ns + "EmployerTPASeparationResponse").Single();
using (cmd4) {
foreach(var param in node.Elements()) {
cmd4.Parameters.AddWithValue(param.Name.LocalName, param.Value);
}
cmd4.ExecuteNonQuery();
}
C#, Linq2Sql, .NET 2.0, SQL 2005 Express
When I run the following code I get a
InvalidCastException unable to cast of type System.Byte[] to System.String
This does not occur on all rows in the table i.e. this code runs fine soemtimes.
I checked there are no columns in the table that linq declares as SYstem.Byte[]
The stack trace says the exception occurs on the linq statement and when I F11
into the code the GetProject is never called the exception occurs before this method
is called.
So I think it is Linq framework bug.
This has got me stumped? any ideas?
[code]
public Project GetProject(int id)
{
var project = (from row in _dbctx.Projects
where row.ProjectID == id
select row).SingleOrDefault();
Project proj = GetProject(project);
return proj;
}
private Project GetProject(TBRServices.Domain.TBR.DataContext.Project sqlproject)
{
Project project = new Project();
project.ProjectID = sqlproject.ProjectID;
project.ProjectName = sqlproject.ProjectName;
project.ProjectDescription = sqlproject.ProjectDescription;
project.ClientID = sqlproject.ClientID;
project.PurchaseOrderNumber = sqlproject.PurchaseOrderNumber;
project.ProjectTotalBillingEstimate = sqlproject.ProjectTotalBillingEstimate;
project.EmployeeID = sqlproject.EmployeeID;
project.ProjectBeginDate = sqlproject.ProjectBeginDate.ToString();
project.ProjectEndDate = sqlproject.ProjectEndDate.ToString();
project.Active = sqlproject.Active;
project.InclGST = sqlproject.InclGST;
project.ContractRate = sqlproject.ContractRate;
project.MarginRate = sqlproject.MarginRate;
project.Notes = sqlproject.Notes;
project.PayrollTax = sqlproject.PayrollTax;
project.EmployeeReference = sqlproject.EmployeeReference;
project.PayReference = sqlproject.PayReference;
project.ProjectLocation = sqlproject.ProjectLocation;
project.ContractTypeID = sqlproject.ContractTypeID;
project.DoNotCalcMarginOrGST = sqlproject.DoNotCalcMarginOrGST;
project.ConvertToInvoice = sqlproject.ConvertToInvoice;
project.AuthFirstname = sqlproject.AuthFirstname;
project.AuthLastname = sqlproject.AuthLastname;
project.AuthEmail = sqlproject.AuthEmail;
project.CapturedDocumentType = sqlproject.CapturedDocumentType;
project.TimesheetProcessingType = sqlproject.TimesheetProcessingType;
project.TimesheetFrequency = sqlproject.TimesheetFrequency;
project.AggregateTimesheet = sqlproject.AggregateTimesheet;
project.AggregateAutomatically = sqlproject.AggregateAutomatically;
project.BusProcEmpCut = sqlproject.BusProcEmpCut;
project.BusProcAgencyCut = sqlproject.BusProcAgencyCut;
project.SendCopyTimesheet = sqlproject.SendCopyTimesheet;
project.TimesheetRecipient1 = sqlproject.TimesheetRecipient1;
project.TimesheetRecipient2 = sqlproject.TimesheetRecipient2;
project.SendCopyInvoice = sqlproject.SendCopyInvoice;
project.PublishedOn = sqlproject.PublishedOn.ToString();
project.SendAggTimesheetsWhenReceived = sqlproject.SendAggTimesheetsWhenReceived;
project.AuthoriseInvoice = sqlproject.AuthoriseInvoice;
project.HourlyDailyMthly = sqlproject.HourlyDailyMthly;
project.EmployeeCategory = sqlproject.EmployeeCategory;
project.AgencyRate = sqlproject.AgencyRate;
project.ConsultantID = sqlproject.ConsultantID;
project.SendCopyInvoiceEmployee = sqlproject.SendCopyInvoiceEmployee;
project.UseClientDetailsForTimesheet = sqlproject.UseClientDetailsForTimesheet;
project.FaxedTimesheet = sqlproject.FaxedTimesheet;
project.TimesheetEditable = sqlproject.TimesheetEditable;
project.IncludeInReport = sqlproject.IncludeInReport;
project.SendLogonEmail = sqlproject.SendLogonEmail;
project.NoticePeriodID = sqlproject.NoticePeriodID;
project.ManagerCanViewPaidUnpaid = sqlproject.ManagerCanViewPaidUnpaid;
project.LesterSalesStaff = sqlproject.LesterSalesStaff;
project.IncludeSalesReport = sqlproject.IncludeSalesReport;
project.CurrencyAccount = sqlproject.CurrencyAccount;
project.LeaveMustBeAuthorisedTimesheet = sqlproject.LeaveMustBeAuthorisedTimesheet;
project.LeaveMustBeAuthorisedLeaveForm = sqlproject.LeaveMustBeAuthorisedLeaveForm;
project.DefaultHoursWorkedWeek = sqlproject.DefaultHoursWorkedWeek;
project.DefaultHoursWorkedDay = sqlproject.DefaultHoursWorkedDay;
project.AccruedLeaveStartDate = sqlproject.AccruedLeaveStartDate.ToString();
project.AllowLeaveMoreThanAccrued = sqlproject.AllowLeaveMoreThanAccrued;
project.IsPaidASalary = sqlproject.IsPaidASalary;
project.AgencyID = sqlproject.AgencyID;
project.SendEmailToManagerToOKLeave = sqlproject.SendEmailToManagerToOKLeave;
project.SpecialPayrollNotes = sqlproject.SpecialPayrollNotes;
project.SpecialInvoicingNotes = sqlproject.SpecialInvoicingNotes;
project.InvoiceTermsMessage = sqlproject.InvoiceTermsMessage;
project.AuthManagerPhone = sqlproject.AuthManagerPhone;
project.LMF = sqlproject.LMF;
project.LMFPercent = sqlproject.LMFPercent;
project.LMFInclInPayRate = sqlproject.LMFInclInPayRate;
project.LMFOnTop = sqlproject.LMFOnTop;
project.AgencyComm = sqlproject.AgencyComm;
project.AgencyCommPercent = sqlproject.AgencyCommPercent;
project.AgencyCommInclInPayRate = sqlproject.AgencyCommInclInPayRate;
project.AgencyCommOnTop = sqlproject.AgencyCommOnTop;
project.PayRateInclMargin = sqlproject.PayRateInclMargin;
project.MarginRatePercent = sqlproject.MarginRatePercent;
project.MarginRateGST = sqlproject.MarginRateGST;
project.MarginRateInclInPayRate = sqlproject.MarginRateInclInPayRate;
project.MarginRateOnTop = sqlproject.MarginRateOnTop;
project.PayRateInclSuper = sqlproject.PayRateInclSuper;
project.PayrollTaxAmount = sqlproject.PayrollTaxAmount;
project.PayrollTaxPercent = sqlproject.PayrollTaxPercent;
project.PayrollTaxInclInPayRate = sqlproject.PayrollTaxInclInPayRate;
project.PayrollTaxOnTop = sqlproject.PayrollTaxOnTop;
project.TypeOfArrangement = sqlproject.TypeOfArrangement;
project.ParameterRequired = sqlproject.ParameterRequired;
project.SpecialPayrollEnabled = sqlproject.SpecialPayrollEnabled;
project.ClientContactUsedReceiptOfInvoiceID = sqlproject.ClientContactUsedReceiptOfInvoiceID;
project.ExcludeEmpNameOnInvoice = sqlproject.ExcludeEmpNameOnInvoice;
project.BPForReporting = sqlproject.BPForReporting;
project.UseGemteqInvoiceFormat = sqlproject.UseGemteqInvoiceFormat;
project.TreatPayrollDetailsSameAsBP = sqlproject.TreatPayrollDetailsSameAsBP;
return project;
}
[/code]
Check the answer to a similar SO question. It will not be the exact answer but may help you find the problem in your query -
Problem with Linq to SQL
unable to cast of type System.Byte[] to System.String
Indicates that a property in sqlproject is stored as byte[] while the corresponding property in project is a string