Entity Framework notes : Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details

May 3, 2015

Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details

// Your code…
// Could also be before try if you know the exception occurs in 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);

.Net notes : Entity Framework

May 1, 2015

‘Unable to update the EntitySet ‘xxxxxxxx’ because it has a DefiningQuery and no element exists in the element to support the current operation.’

Please check:

1. Make sure you have ”xxxxxxx” table in your datgbase

2. Make sure you have the Primary Key in that table

3. If the the table and Primary Key are existing, please updated the Entity map and publish again.

Asp.Net : Unable to make the session state request to the session state server

April 24, 2015

Asp.Net : Unable to make the session state request to the session state server

Unable to make the session state request to the session state server

That error message means the ASP.NET State service is not running in services.msc

Please select a row error popup message

April 2, 2015

In IE 11
if you are getting “Please select a row” error pop up message then u have to check the below solution.

Tools – >Compatibility View settings ->

uncheck the checkbox of “Display intranet sites in Compatibility View”

Please select a row

SqlServer notes : sqlserver script to find a string in entire database

April 1, 2015


DECLARE @SearchString VARCHAR(100)

— ——————————————
— Enter the string to be searched for here :

SET @SearchString=’bracket’
— ——————————————

SELECT @SQL = @SQL + ‘SELECT CONVERT(VARCHAR(MAX),COUNT(*)) + ” matches in column ”+”’
+ C.name + ”’+” on table ” + ”’ + SC.name + ‘.’ + T.name +
”’ [Matches for ”’+@SearchString+”':] FROM ‘ +
QUOTENAME(SC.name) + ‘.’ + QUOTENAME(T.name) + ‘ WHERE ‘ + QUOTENAME(C.name) +
‘ LIKE ”%’ + @SearchString +
‘%” HAVING COUNT(*)>0 UNION ALL ‘ +CHAR(13) + CHAR(10)
FROM sys.columns C
JOIN sys.tables T
ON C.object_id=T.object_id
JOIN sys.schemas SC
ON SC.schema_id=T.schema_id
JOIN sys.types ST
ON C.user_type_id=ST.user_type_id
JOIN sys.types SYST
ON ST.system_type_id=SYST.user_type_id
AND ST.system_type_id=SYST.system_type_id
WHERE SYST.name IN (‘varchar’,’nvarchar’,’text’,’ntext’,’char’,’nchar’)
ORDER BY T.name, C.name

— Strip off the last UNION ALL



Sharepoint : Div tag with ExternalClass

December 16, 2014

Every time I insert enhanced rich text in a field in SharePoint and
save it, SharePoint inserts DIV tags with an external class reference
around my content.

Why does it do this? Where is this class? What does it specify?

have multilined text field. When it is empty it is rendering in the list view as below. Can anyone tell me why and how to fix it?

– See more at: http://www.go4sharepoint.com/Forum/externalclass-enhanced-rich-text-fields-7091.aspx#sthash.lS18KFks.dpuf

Solution :

You can use Regex.Replace(currentItem[“Your Field Name”].ToString(), “”, string.Empty); Basically this will replace your div tag with empty string so you will get your plain text


In Jquery use regex like this – stringvalue.Replace(“”, “”);

Convert File to Byte Array and Byte Array to Files

November 14, 2014


In this article, let us see how to convert a file content to a byte array and restore the original content from the byte array and display it in its original file format such as pdf, doc, xls, rtf, jpeg, png etc.

Step 1: Create an ASP.Net application and add a class Document.

public class Document {
public int DocId { get; set; }
public string DocName { get; set; }
public byte[] DocContent { get; set; }

Step 2: Create a file of format doc/pdf/rtf etc. and convert the file content to a ByteArray using the following method. Then create an object of type Document and assign the Docname and DocContent property values from filename and filecontent.

public Document FileToByteArray(string fileName) {
byte[] fileContent = null;

System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
long byteLength = new System.IO.FileInfo(fileName).Length;
fileContent = binaryReader.ReadBytes((Int32)byteLength);
Document = new Document();
Document.DocName = fileName;
Document.DocContent = fileContent;
return Document ;

Step 3: Now we need to convert the byte array back again to the file content and display it to the user with download options. For that I am using another method, ShowDocument, as below:

private void ShowDocument(string fileName, byte[] fileContent)
//Split the string by character . to get file extension type
string[] stringParts = fileName.Split(new char[] { ‘.’ });
string strType = stringParts[1];
Response.AddHeader(“content-disposition”, “attachment; filename=” + fileName);
//Set the content type as file extension type
Response.ContentType = strType;
//Write the file content

Step 4: In the page_load event, I have the following code, which will read the contents from the file and convert it to a ByteArray using the FileToByteArray method and convert it back to content using the ShowDocument method.

protected void Page_Load(object sender, EventArgs e)
FileToByteArray(“C:\\Users\\santhosh.kumar\\Documents\\Test for rht format.rtf”);
ShowDocument(Document.DocName, Document.DocContent);


Get every new post delivered to your Inbox.