Here I am able to add the data in more than one table. Let i have 3 tables User, Franchise and Fee.
I am not able to update the data in more than one table,it throwing the exception:
A referential integrity constraint violation occurred: The property value(s) of 'User.Id' on one end of a relationship do not match the property value(s) of 'Franchise.UserId' on the other end.
Code:
public MessageResult SaveAndUpdateFranchisee(UserViewModel model)
{
var result = new MessageResult();
try
{
User userData = new User();
Franchise franchiseData = new Franchise();
var ExistUser = db.Users.Where(a => a.Id == model.Id).FirstOrDefault();
//Update record
if (model.Id > 0)
{
Fee feeData = new Fee
{
FranchiseeFee = model.FranchiseeFee,
PaymentTermsFranchiseFee = model.PaymentTermsFranchiseFee,
EquipmentCost = model.EquipmentCost,
PaymentTermsEquipmentCost = model.PaymentTermsEquipmentCost,
OtherFee = model.OtherFee,
PaymentTermsOtherFee = model.PaymentTermsOtherFee,
ConsumableStock = model.ConsumableStock,
PaymentTermsConsumableStock = model.PaymentTermsConsumableStock,
FrozenFoodStock = model.FrozenFoodStock,
PaymentTermsFrozenFoodStock = model.PaymentTermsFrozenFoodStock,
TotalAmountDue = model.TotalAmountDue,
TotalAmountPaid = model.TotalAmountPaid,
BalanceAmount = model.BalanceAmount,
LoyaltyFeePercentage = model.LoyaltyFeePercentage,
FixedMonthlyFee = model.FixedMonthlyFee,
Note = model.Note,
UserId = model.CurrentUserId,
LOIDocUrl = model.LOIDocUrl,
ModifiedDate = DateTime.Now
};
ExistUser.Email = model.Email;
//var pwd = SecutiryServices.EncodePasswordToBase64(model.Password);
//userData.Password = pwd;
ExistUser.Password = model.Password;
ExistUser.FirstName = model.FirstName;
ExistUser.MiddleName = model.MiddleName;
ExistUser.LastName = model.LastName;
ExistUser.FullName = model.FullName;
ExistUser.MobileNo = model.MobileNo;
ExistUser.ModifyDate = DateTime.Now;
franchiseData.Name = model.FullName;
franchiseData.MobileNo = model.MobileNo;
franchiseData.AlternateNo = model.AlternetNo;
franchiseData.CompanyPhoneNo = model.PhoneNo;
franchiseData.Address = model.Address;
franchiseData.City = model.City;
franchiseData.State = model.State;
franchiseData.PinCode = model.PinCode;
franchiseData.CompanyName = model.CompanyName;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyCity = model.CompanyCity;
franchiseData.CompanyState = model.CompanyState;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyPinCode = model.CompanyPinCode;
franchiseData.ModifiedDate = DateTime.Now;
userData.Franchises.Add(franchiseData);
foreach (var item in userData.Franchises)
{
item.Fees.Add(feeData);
}
db.Users.Attach(userData);
db.Entry(userData).State = System.Data.Entity.EntityState.Modified;
//db.Users.Add(userData);
db.SaveChanges();
result.Message = "Your franchise has been updated successfully..";
result.Status = true;
}
//For Insert recored..
else
{
Fee feeData = new Fee
{
FranchiseeFee = model.FranchiseeFee,
PaymentTermsFranchiseFee = model.PaymentTermsFranchiseFee,
EquipmentCost = model.EquipmentCost,
PaymentTermsEquipmentCost = model.PaymentTermsEquipmentCost,
OtherFee = model.OtherFee,
PaymentTermsOtherFee = model.PaymentTermsOtherFee,
ConsumableStock = model.ConsumableStock,
PaymentTermsConsumableStock = model.PaymentTermsConsumableStock,
FrozenFoodStock = model.FrozenFoodStock,
PaymentTermsFrozenFoodStock = model.PaymentTermsFrozenFoodStock,
TotalAmountDue = model.TotalAmountDue,
TotalAmountPaid = model.TotalAmountPaid,
BalanceAmount = model.BalanceAmount,
LoyaltyFeePercentage = model.LoyaltyFeePercentage,
FixedMonthlyFee = model.FixedMonthlyFee,
Note = model.Note,
UserId = model.CurrentUserId,
LOIDocUrl = model.LOIDocUrl,
CreatedDate = DateTime.Now
};
userData.Email = model.Email;
//var pwd = SecutiryServices.EncodePasswordToBase64(model.Password);
//userData.Password = pwd;
userData.Password = model.Password;
userData.FirstName = model.FirstName;
userData.FullName = model.FirstName + " " + model.LastName;
userData.LastName = model.LastName;
userData.MobileNo = model.MobileNo;
userData.IsActive = true;
userData.IsDelete = false;
userData.CreatedDate = DateTime.Now;
userData.UserTypeId = 2;
franchiseData.CompanyId = model.CurrentUserId;
franchiseData.Name = userData.FullName;
franchiseData.MobileNo = model.MobileNo;
franchiseData.AlternateNo = model.AlternetNo;
franchiseData.Address = model.Address;
franchiseData.City = model.City;
franchiseData.State = model.State;
franchiseData.PinCode = model.PinCode;
franchiseData.CompanyName = model.CompanyName;
franchiseData.CompanyPhoneNo = model.PhoneNo;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyCity = model.CompanyCity;
franchiseData.CompanyState = model.CompanyState;
franchiseData.CompanyAddress = model.CompanyAddress;
franchiseData.CompanyPinCode = model.CompanyPinCode;
franchiseData.CreatedDate = DateTime.Now;
franchiseData.IsActive = true;
userData.Franchises.Add(franchiseData);
foreach (var item in userData.Franchises)
{
item.Fees.Add(feeData);
}
db.Users.Add(userData);
db.SaveChanges();
//db.AddUserRole(userData.Id, 4);
result.Message = "Your franchisee has been created successfully..";
result.Status = true;
}
return result;
}
catch (Exception ex)
{
result.Message = "We are unable to process your request at this time. Please try again later.";
result.Status = false;
return result;
}
}
The error message is straightforward - your code is creating a new Franchise object but it never sets the franchiseData.UserId property.
Add this to your franchiseData population code before you call db.SaveChanges():
franchiseData.UserId = model.CurrentUserId;
BTW, you should add code verify that the current user has permission to set foreign-key reference properties (like UserId) directly from values read from submitted forms because otherwise any user could enter Id values belonging to other users and gain access to information they shouldn't have access to - or otherwise alter with your database.
I have next code
var D3s = new Array(9);
var D3n: float[];
result = Mine(result);
function Mine(block) {
D3n = new float[5];
var init = false;
if (block.startsWith("##new#")) {
block = block.replace("##new#", "");
init = true;
D3n[3] = 16;
}
var s1 = block.split("&");
s1.forEach(foreachBlocks);
if (init) {
//set default values
D3n[1] = 0;
D3s[6] = "ff";
D3n[2] = 0;
}
return TurnM79();
}
and error: CompilationErrorsException: script(9,9): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown identifier: 'D3n'.
what wrong?
I have migrated my application to Dev Express 15.2.After migration data is not exporting in GridView style.Like alternate row color,Font ..etc.Do we have any option to export the data same as like in grid.
Designer:
this.gridView1.Appearance.EvenRow.BackColor = System.Drawing.Color.Khaki;
this.gridView1.Appearance.EvenRow.Options.UseBackColor = true;
this.gridView1.Appearance.GroupPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(74)))), ((int)(((byte)(74)))), ((int)(((byte)(74)))));
this.gridView1.Appearance.GroupPanel.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold);
this.gridView1.Appearance.GroupPanel.Options.UseBackColor = true;
this.gridView1.Appearance.GroupPanel.Options.UseFont = true;
this.gridView1.Appearance.HeaderPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.gridView1.Appearance.HeaderPanel.Options.UseBackColor = true;
this.gridView1.AppearancePrint.EvenRow.BackColor = System.Drawing.Color.Khaki;
this.gridView1.AppearancePrint.EvenRow.Options.UseBackColor = true;
this.gridView1.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
this.gridColumn1,
this.gridColumn2,
this.gridColumn3,
this.gridColumn4,
this.gridColumn5});
this.gridView1.GridControl = this.gridControl1;
this.gridView1.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, "OrderID", null, "")});
this.gridView1.Name = "gridView1";
this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
Code in cs file
if(ext == "xlsx")
{
XlsxExportOptionsEx options = new XlsxExportOptionsEx();
options.ShowGridLines = false;
options.AllowSortingAndFiltering = DevExpress.Utils.DefaultBoolean.False;
options.ExportType = DevExpress.Export.ExportType.WYSIWYG;
exportView.ExportToXlsx(filename, options);
}
By setting following properties issue is solved.
((DevExpress.XtraGrid.Views.Grid.GridView)gridControl1.MainView).OptionsPrint.EnableAppearanceEvenRow = true;
((DevExpress.XtraGrid.Views.Grid.GridView)gridControl1.MainView).OptionsPrint.UsePrintStyles = false;
I have the following conf database
$db['default']['hostname'] = 'xx.xx.xx.xx,1433';
$db['default']['username'] = 'user';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Codeigniter get me the Unable to connect to database using the parameters entered...what's wrong? i try the following connection for $db['default']['hostname']
$db['default']['hostname'] = 'xx.xx.xx.xx,1433';
$db['default']['hostname'] = '(xx.xx.xx.xx),1433';
$db['default']['hostname'] = 'xx.xx.xx.xx:1433';
and it don't work
Any ideas? Thanks
Set
$db['default']['pconnect'] = false;
That should work.
You added hostname and port number together codeigniter has a setting to define port number
$db['default']['hostname'] = 'xx.xx.xx.xx';
$db['default']['username'] = 'user';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = 1433;
For more details go to http://ellislab.com/codeigniter/user-guide/database/configuration.html
i have this method in my domainService
public IQueryable Getbl()
{
var qer = from t in this.ObjectContext.lignes_bl
from t0 in this.ObjectContext.entete_bl
where
t.NO_BL == t0.NO_BL
orderby
t.NO_BL,
t.NO_LIGNE
select new
{
IDentete_bl = t0.IDENTETE_BL,
NO_BL = t0.NO_BL,
DATE_BL = t0.DATE_BL,
FAC_AVOIR = t0.FAC_AVOIR,
REF_BL = t0.REF_BL,
CODE_CLIENT = t0.CODE_CLIENT,
NOM_CLIENT = t0.NOM_CLIENT,
ADRESSE = t0.ADRESSE,
CODE_PAYS = t0.CODE_PAYS,
VILLE = t0.VILLE,
CODE_POSTAL = t0.CODE_POSTAL,
ZONE = t0.ZONE,
TEL_FAX = t0.TEL_FAX,
CODE_ADL = t0.CODE_ADL,
NOM_ADL = t0.NOM_ADL,
ADRESSE_ADL = t0.ADRESSE_ADL,
CODE_POSTAL_ADL = t0.CODE_POSTAL_ADL,
VILLE_ADL = t0.VILLE_ADL,
MT_TTC_BL = t0.MT_TTC_BL,
CODE_PAYS_ADL = t0.CODE_PAYS_ADL,
TEL_FAX_ADL = t0.TEL_FAX_ADL,
REM = t0.REM,
CODE_REGLEMENT = t0.CODE_REGLEMENT,
NO_FACTURE = t0.NO_FACTURE,
DATE_FACTURE = t0.DATE_FACTURE,
CODE_COMPTA = t0.CODE_COMPTA,
SITE = t0.SITE,
CODE_COMMERCIAL = t0.CODE_COMMERCIAL,
NBR_COLIS = t0.NBR_COLIS,
NOM_TRANSPORTEUR = t0.NOM_TRANSPORTEUR,
FACTURE_DIRECTE = t0.FACTURE_DIRECTE,
MOIS_FACTURE = t0.MOIS_FACTURE,
CLE_SITE_MOIS_FAC = t0.CLE_SITE_MOIS_FAC,
CLE_SITE_FD_CC = t0.CLE_SITE_FD_CC,
CLE_SITE_FD = t0.CLE_SITE_FD,
CLE_SITE_FD_CC_EDIT = t0.CLE_SITE_FD_CC_EDIT,
ARCHIVAGE = t0.ARCHIVAGE,
NO_TVA_CL = t0.NO_TVA_CL,
numero = t0.numero,
Bis = t0.bis,
voie = t0.voie,
P_identite = t0.P_identite,
p_numero = t0.p_numero,
p_du = t0.p_du,
p_par = t0.p_par,
nais_du = t0.nais_du,
nais_ville = t0.nais_ville,
nais_dep = t0.nais_dep,
nais_pays = t0.nais_pays,
num_siren = t0.num_siren,
id_bon_ademe = t0.id_bon_ademe,
poids_ademe_vhu = t0.poids_ademe_vhu,
CODE_BROYEUR = t0.CODE_BROYEUR,
IDlignes_bl = t.IDLIGNES_BL,
CODE_CLIENT_LI = t.CODE_CLIENT,
NO_BL_LI = t.NO_BL,
DATE_BL_LI = t.DATE_BL,
FAC_AVOIR_LI = t.FAC_AVOIR,
CODE_ARTICLE = t.CODE_ARTICLE,
NO_VEHICULE = t.NO_VEHICULE,
DESIGNATION = t.DESIGNATION,
QTE = t.QTE,
PU_HT = t.PU_HT,
REM_LI = t.REM,
CODE_TVA = t.CODE_TVA,
TAUX_TVA = t.TAUX_TVA,
NO_LIGNE = t.NO_LIGNE,
TYPE_ARTICLE = t.TYPE_ARTICLE,
LIB_LIBRE = t.LIB_LIBRE,
DESI_ARTICLE = t.DESI_ARTICLE,
CODE_GARANTIE = t.CODE_GARANTIE,
NO_FACTURE_LI = t.NO_FACTURE,
CODE_REGLEMENT_LI = t.CODE_REGLEMENT,
SITE_LI = t.SITE,
LIB_MODELE = t.LIB_MODELE,
PA_HT_TTC = t.PA_HT_TTC,
PU_NET = t.PU_NET,
PU_TTC = t.PU_TTC,
code_id_article = t.code_id_article,
site_stockage = t.site_stockage,
sans_trait_haut = t.sans_trait_haut,
nom_article_unique_demonter = t.nom_article_unique_demonter,
code_ademe_ligne = t.code_ademe_ligne,
poids_ademe = t.poids_ademe,
type_article_ademe = t.type_article_ademe,
consistance = t.consistance,
conditionnement = t.conditionnement,
nombre_carcasse = t.nombre_carcasse,
num_vehicule_entretien = t.num_vehicule_entretien,
num_immat_vehi_entretien = t.num_immat_vehi_entretien
};
return qer.AsQueryable();
and i have this code in button ,the problem is does not contain a definition for Getbl ?
DomainService1 testContext = new DomainService1();
private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
InitializeComponent();
var res = testContext.Getbl();
}
Getbl returns an enumeration of an anonymous type. Anonymous types have only internal accessibility hence getbl is not included in service since that would in effect mean it would have return a list of type instances that should not be exposed publically.
Create a public class the has the list of Properties you want to return and include a new instance of this public class in your Select projection rather than using an anonymous type.
in addition to AnthonyWJones answer:
Use LoadOperation to get the data from the server:
LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
CustomerGrid.ItemsSource = loadOp.Entities;
Note: Your method will have an appendix "Query" which RIA adds to Query methods.