try
{
// Your code...
// Could also be before try if you know the exception occurs in SaveChanges
context.SaveChanges();
}
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
Every Question..What does it mean? Why is this? How it works?
Microsoft .Net (pronounced dot (.) net) may be a package element that runs on the Windows software package.
.Net provides tools and libraries that change developers to form Windows package a lot of quicker and easier.
Microsoft describes it as:".Net is that the Microsoft internet Service strategy to attach data, people,
system and devices through software".I'm Choulla Naresh..!
Tuesday, November 21, 2017
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Tuesday, October 31, 2017
Join Query Multiple Tables Order by descending Order
var year = (from ep in _adminContext.table1
join e in _adminContext.table2 on ep.idequals e.id
join t in _adminContext.table3 on e.idequals t.id
orderby t.Date descending
where t.status == "A"
select new
{
id= ep.id
}).FirstOrDefault();
asynchronous option to be false
the asynchronous choice to be false to induce a synchronous Ajax request. Then your asking will set some information before your Main perform return.
Here's what your code would seem like if modified as suggested:
Here's what your code would seem like if modified as suggested:
beforecreate: function (node, targetNode, type, to) {
jQuery.ajax({
url: 'http://example.com/catalog/create/' + targetNode.id
+ '?name=' + encode(to.inp[0].value),
success: function (result) {
if (result.isOk == false)
alert(result.message);
},
async: false
});
}
<script>
// ...
$.ajax(... async: false ...); // Hey
browser! first complete this request,
// then go
for other codes
$.ajax(...); // Executed
after the completion of the previous async:false request.
</script>
Difference between Managed and unmanaged code
Managed code -
Executed by the CLR instead of being executed by the operating system.
Unmanaged code - Executed directly by the operating system(OS) and not by the CLR
Unmanaged code - Executed directly by the operating system(OS) and not by the CLR
Adding an existing project to GitHub using the command line
How to Add project to git hub
1) Create new repository Copy Repository Url
2) Open ur project in Visual Studio
3) type: git init
git add *
ls
And Execte git hub generated commands
1) Create new repository Copy Repository Url
2) Open ur project in Visual Studio
3) type: git init
git add *
ls
And Execte git hub generated commands
Build Connection String Dynamically
Entities _context = (Entities)HttpContext.Current.Session[SessionNames.xContext];
using WebSession = System.Web.HttpContext;
#region Build Connection String Dynamically
public string BuildConnectionString(string dataSource, string database, string userId, string password)
{
// string connect = BuildConnectionString(dataSource,
custDbName, dbUserId, dbUserPassword);
EntityConnectionStringBuilder retval = new EntityConnectionStringBuilder();
//// Build the connection string from the provided
datasource and database
try
{
SqlConnectionStringBuilder sqlBuilder =
new SqlConnectionStringBuilder
{
DataSource = "x.x.x.x",
InitialCatalog = "xTemplate",
UserID = "x",
Password = "x",
IntegratedSecurity = false,
MultipleActiveResultSets = true
};
retval = new EntityConnectionStringBuilder
{
Metadata = "res://*/x.Client.csdl|res://*/x.Client.ssdl|res://*/x.Client.msl",
Provider = "System.Data.SqlClient",
ProviderConnectionString =
sqlBuilder.ToString()
};
BuildDatabaseContext(retval.ToString());
}
catch
(Exception e)
{
throw;
}
return retval.ToString();
}
public void BuildDatabaseContext(string connectionString)
{
try
{
StoreContext(connectionString);
}
catch
(Exception e)
{
throw;
}
}
public void StoreContext(string connect)
{
try
{
Entities context = new Entities(connect);
WebSession.Current.Session[SessionNames.xContext] = context;
}
catch
(Exception e)
{
throw;
}
}
#endregion
Monday, October 16, 2017
Thursday, October 12, 2017
* operator has higher precedence than +
// The * operator has higher precedence than + so this expression evaluates to 7:
1 + 2 * 3
// (See book for operator precedence table)
1 + 2 * 3
// (See book for operator precedence table)
// T4 code generation is enabled for model 'c:\users\scala\documents\visual studio 2013\Projects\entityFramework\entityFramework\EntityModel.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. // If no context and entity classes have been generated, it may be because you created an empty model but // have not yet chosen which version of Entity Framework to use. To generate a context class and entity // classes for your model, open the model in the designer, right-click on the designer surface, and // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation // Item...'
To generate a context class and entity classes for your model, open the model in the designer, right-click on the designer surface, and select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation Item...'.
'Add Code Generation Item...' will do the trick. You should basically choose and add one or more T4 templates to actually generate the entities. More info here. Also take a look at this answer. It might help to make things clear.
browser close event
Trying to detect browser close event
------------------------------------------
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(function () {
$("a").not('#lnkLogOut').click(function () {
window.onbeforeunload = null;
});
$(".btn").click(function () {
window.onbeforeunload = null;
});
});
================================================
How to capture the browser window close event?
----------------------------
var inFormOrLink;
$('a').on('click', function() { inFormOrLink = true; });
$('form').on('submit', function() { inFormOrLink = true; });
$(window).on("beforeunload", function() {
return inFormOrLink ? "Do you really want to close?" : null;
})
For jQuery versions older than 1.7, try this:
var inFormOrLink;
$('a').live('click', function() { inFormOrLink = true; });
$('form').bind('submit', function() { inFormOrLink = true; });
$(window).bind("beforeunload", function() {
return inFormOrLink ? "Do you really want to close?" : null;
})
------------------------------------------
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(function () {
$("a").not('#lnkLogOut').click(function () {
window.onbeforeunload = null;
});
$(".btn").click(function () {
window.onbeforeunload = null;
});
});
================================================
How to capture the browser window close event?
----------------------------
var inFormOrLink;
$('a').on('click', function() { inFormOrLink = true; });
$('form').on('submit', function() { inFormOrLink = true; });
$(window).on("beforeunload", function() {
return inFormOrLink ? "Do you really want to close?" : null;
})
For jQuery versions older than 1.7, try this:
var inFormOrLink;
$('a').live('click', function() { inFormOrLink = true; });
$('form').bind('submit', function() { inFormOrLink = true; });
$(window).bind("beforeunload", function() {
return inFormOrLink ? "Do you really want to close?" : null;
})
Subscribe to:
Posts (Atom)