Friday, December 8, 2017

Potential runtime violation of table MigrationHistory's keys (MigrationHistory.MigrationId): Columns (MigrationHistory.MigrationId) are mapped to EntitySet MigrationHistories's properties (MigrationHistories.MigrationId) on the conceptual side but they do not form the EntitySet's key properties (MigrationHistories.ContextKey, MigrationHistories.MigrationId).

Error a pair of Error 3002: drawback in mapping fragments beginning at line 2532:Potential runtime violation of table MigrationHistory's keys (MigrationHistory.MigrationId): Columns (MigrationHistory.MigrationId) ar mapped to EntitySet MigrationHistories's properties (MigrationHistories.MigrationId) on the abstract aspect however they are doing not type the EntitySet's key properties (MigrationHistories.ContextKey, MigrationHistories.MigrationId).


The reason was in strange update results of EF model update operation. table seeable (database) continues to be a key, however in model read it had been deleted(automatically) from set of keys. however not everyplace or one thingelse... therefore the resolution - Set Entity Key to False and Nullable to True not for brand new fields, except for table

<EntityType Name="MigrationHistory">
          <Key>
            <PropertyRef Name="MigrationId" /> Find MigrationHistory
     <PropertyRef Name="ContextKey" /> Add this keys
    </Key>
          <Property Name="MigrationId" Type="nvarchar" MaxLength="150" Nullable="false" />
          <Property Name="ContextKey" Type="nvarchar" MaxLength="300" Nullable="false" />
          <Property Name="Model" Type="varbinary(max)" Nullable="false" />
          <Property Name="ProductVersion" Type="nvarchar" MaxLength="32" Nullable="false" />
        </EntityType>

Tuesday, November 21, 2017

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

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;
}

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:

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

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

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

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)

// 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.