Translate

Monday, 25 June 2018

how to enable lazy loading entire project using entitty framework in .net framework I use in Context class


I set it in the constructor of  Context class  i.e. this.Configuration.LazyLoadingEnabled = false;

Below is the code snippet.

 public partial class PabitraEntities : DbContext
    {
        public PabitraEntities()
            : base("name=PabitraEntities")
        {         
            this.Configuration.LazyLoadingEnabled = false;
        }

      protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

  public virtual DbSet<CountryMaster> CountryMasters { get; set; }
}

Tuesday, 19 June 2018

html control in array for looping

foreach (HtmlControl htm in new HtmlControl[] { trCRCCName, trCRCCIdentification, trCRCCMobile }) htm.Visible = false;

Tuesday, 8 May 2018

sql : Generate Row number i.e. Row_Number() in a table


CREATE TABLE TblGen_ROW_NUMBER
(
Name VARCHAR(100),
City VARCHAR(100)
)
INSERT INTO TblGen_ROW_NUMBER(Name,City)VALUES('PABITRA','BHUBANESWAR')
INSERT INTO TblGen_ROW_NUMBER(Name,City)VALUES('ASHWIN','CUTTACK')
INSERT INTO TblGen_ROW_NUMBER(Name,City)VALUES('ARRYA','NAKHARA')
SELECT ROW_NUMBER() OVER(ORDER BY Name)AS ID, Name,City FROM TblGen_ROW_NUMBER
SELECT ROW_NUMBER() OVER(ORDER BY Name DESC)AS ID, Name,City FROM TblGen_ROW_NUMBER




Saturday, 28 April 2018

sql : last date of the month

SELECT DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, GETDATE()) + 1, 0))
SELECT convert(varchar,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, GETDATE()) + 1, 0)),103)

Thursday, 4 January 2018

DataTable to JSON using c#, Ado.net

use this code :

Out Put :





used namespace 

using System.Collections.Generic;
using System.Web.Script.Serialization;

using System.Data;




public string DataTableToJSON()
    {
        DataTable dtCustomer = new DataTable();
        dtCustomer.Columns.AddRange(
                              new DataColumn[]
                              { new DataColumn("ID", typeof(int)),
                                new DataColumn("Name", typeof(string)),
                                new DataColumn("City", typeof(string))
                              }
                              );
        // Add value to the related column
        dtCustomer.Rows.Add(1001, "PABITRA BEHERA","Bhubaneswar");
        dtCustomer.Rows.Add(1002, "Arya Kumar", "Cuttack");
        dtCustomer.Rows.Add(1003, "Mr Roket(Braja)", "Nayagard");
        dtCustomer.Rows.Add(1004, "Mr Trupti", "Bhadrak");
     
        JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
        List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>();
        Dictionary<string, object> childRow;
        foreach (DataRow row in dtCustomer.Rows)
        {
            childRow = new Dictionary<string, object>();
            foreach (DataColumn col in dtCustomer.Columns)
            {
                childRow.Add(col.ColumnName, row[col]);
            }
            parentRow.Add(childRow);
        }
        return jsSerializer.Serialize(parentRow);

    }


Call the function in page load
i.e.
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Response.Write(DataTableToJSON()); 
        }

    }

Monday, 1 January 2018

HTML5 required attribute Custom user message

Scenario where I need the Custom Message

Here I used an input control  i.e. to input user as Customer name.

<input type="text" id="txtCustomerName"  required>

For validation  I need show " Customer name is required  !" where as the current input show me an message like "please fill out this field."

So I need to change the default error message to custom error message. My custom error message with tag is as follows.


<input type="text" id="txtCustomerName" required placeholder="Enter Customer name"
 oninvalid="this.setCustomValidity('Customer name is required  !')" oninput="setCustomValidity('')">




Details Code :

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<form >
<input type="text" id="txtCustomerName"  required>
  <br>
  <br>
<input type="text" id="txtCustomerName" 
       required placeholder="Enter Customer name"

 oninvalid="this.setCustomValidity('Customer name is required  !')"
       oninput="setCustomValidity('')">
<br>
  <br>
 <input type="submit" value="SUBMIT">

</form>
</body>
</html>








Wednesday, 27 December 2017

html li bullet list, square,circle numbering

The following type can we specify in li these are as follows.
type="1|a|A|i|I|disc|circle|square"

I have create some sample tag as follows.

<ul>
  <li type="1">PABITRA</li>
  <li type="1">ARYA</li>
  <li type="1">BRAJA</li>
</ul>

<ul>
  <li type="a">PABITRA</li>
  <li type="a">ARYA</li>
  <li type="a">BRAJA</li>
</ul>


<ul>
  <li type="A">PABITRA</li>
  <li type="A">ARYA</li>
  <li type="A">BRAJA</li>
</ul>

<ul>
  <li type="i">PABITRA</li>
  <li type="i">ARYA</li>
  <li type="i">BRAJA</li>
</ul>

<ul>
  <li type="I">PABITRA</li>
  <li type="I">ARYA</li>
  <li type="I">BRAJA</li>
</ul>

<ul>
  <li type="disc">PABITRA</li>
  <li type="disc">ARYA</li>
  <li type="disc">BRAJA</li>
</ul>


<ul>
  <li type="square">PABITRA</li>
  <li type="square">ARYA</li>
  <li type="square">BRAJA</li>
</ul>