Wednesday, December 10, 2014

'System.Linq.IQueryable' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable' could be found

Error: 'System.Linq.IQueryable' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable' could be found

Solution: Add namespace System.Data.Entity; 
Actually Include is not an extension method on Queryable, so it doesn't come with all the usual LINQ methods. 
If you are using Entity Framework, you need to import namespace System.Data.Entity:
Read More

Tuesday, December 9, 2014

the type or namespace name 'expression' could not be found

To remove error "the type or namespace name 'expression' could not be found" Add namespace System.Linq.Expressions. as normally System.Linq is there in using part by default and expression class is under system.Linq.Expressions so we have to make it also in using.
Read More

Thursday, November 6, 2014

Best Practices for Code Review


..http://support.smartbear.com/pdf/11_Best_Practices_for_Peer_Code_Review.pdf
Read More

The cast to value type 'Double' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type


The cast to value type 'Double' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type OR The cast to value type 'Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type Solution: Put conversion on values before putting it in functions like Avg, Sum etc like: In below code we have put conversion to decimal in average function.
var res =(from profile in dbModel.ProfileMasters
                                         select new
                                         {
                                             ProfileID = profile.ProfileId,
                                             Profile = profile.ClientName,
                                             Tasks= profile.TaskMasters.Count(),
                                             AverageTime = profile.TaskMasters.Select(x => EntityFunctions.DiffMinutes(x.StartTime, x.EndTime)).Average(y => (decimal?)y.Value),
                                             LastTime = profile.TaskMasters.Max(x=>x.StartTime)
                                         }).ToList();

Read More

DbArithmeticExpression arguments must have a numeric common type


DbArithmeticExpression arguments must have a numeric common type Solution: we can't put datediff directly in linq / lambda.. instead of that we should use like : EntityFunctions.DiffMinutes Eg:
              dgvProfiles.DataSource = (from profile in dbModel.ProfileMasters
                                         select new
                                         {
                                             ProfileID = profile.ProfileId,
                                             Profile = profile.ClientName,
                                             Tasks= profile.TaskMasters.Count(),
                                             AverageTime = profile.TaskMasters.Select(x => EntityFunctions.DiffMinutes(x.StartTime, x.EndTime)).Average(y => (decimal?)y.Value),
                                             LastTime = profile.TaskMasters.Max(x=>x.StartTime)
                                         }).ToList();
Read More

Thursday, April 3, 2014

The maximum message size quota for incoming messages (65536) has been exceeded


System.ServiceModel.CommunicationException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. Just increase the MaxReceivedMessageSize if its in client (who is accessing wcf ) then got to app config and change that size like:
Read More

Wednesday, March 26, 2014

Change schema of all tables in database


To change schema of any table/stored procedure you can use this command: ALTER SCHEMA NewSchemaName TRANSFER OldSchemaName.ObjectName But when you want to change schema of all table/sp of a database then its not a good idea to write such lines for all objects. better idea is to generate such script and then run it.. to generate such script for all tables, stored procedures and views, you can use below script.
SELECT 'ALTER SCHEMA NewSchemaName TRANSFER ' + SysSchemas.Name + '.' + DbObjects.Name + ';'
FROM sys.Objects DbObjects
INNER JOIN sys.Schemas SysSchemas ON DbObjects.schema_id = SysSchemas.schema_id
WHERE SysSchemas.Name = 'OldSchemaName'
AND (DbObjects.Type IN ('U', 'P', 'V'))
now just copy the output of this script and run...

Compiled by: Rajesh Rolen

Read More

Saturday, March 22, 2014

Prevent addition of default paragraph tag by ckeditor


to prevent addition of default paragraph tag

by ckeditor we have to add below lines in config.js

CKEDITOR.editorConfig = function (config) {
    config.enterMode = CKEDITOR.ENTER_BR;
    config.shiftEnterMode = CKEDITOR.ENTER_BR;
Read More

Thursday, March 13, 2014

HTTP could not register URL . Your process does not have access rights to this namespace


HTTP could not register URL http://+:8080/FileTranfer/.

Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).

 The issue is that the URL is being blocked from being created by Windows.

 Steps to fix:
Run command prompt as an administrator.
 Add the URL to the ACL netsh http add urlacl url=http://+:8080/FileTranfer/ user=mylocaluser
Read More

Saturday, February 22, 2014

set entity framework connection string programmatically


set entity framework connection string programmatically Error: Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception Solution:
   public static string GetConnectionString(ProfileMaster profile)
        {
            //return string.Format("data source={0};initial catalog={1};user id={2};password={3} multipleactiveresultsets=True;App=EntityFramework", profile.DatabaseIP, profile.DatabaseName, profile.UserName, profile.Password);
            string providerName = "System.Data.SqlClient";
            string serverName = profile.DatabaseIP;
            string databaseName = profile.DatabaseName;

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
            new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.IntegratedSecurity = true;

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
            new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/Models.MoviesDB.csdl|
                        res://*/Models.MoviesDB.ssdl|
                        res://*/Models.MoviesDB.msl";
            return entityBuilder.ToString();
        }

Compiled By: Rajesh Rolen

Read More

Saturday, January 18, 2014

Debugging Dll


System.Diagnostics.Debugger.Break();
Read More

Error for enumerable when using JsonConvert.SerializeObject


[Serializable]
    public abstract class Entity
    {
        public Entity()
        {
        }

        public Entity(int id)
        {
            this.Id = id;
        }

        public virtual int Id { get; set; }

        public override bool Equals(object obj)
        {
            Entity other = (Entity)obj;
            return this.Id == other.Id;
        }

        public override int GetHashCode()
        {
            return this.Id.GetHashCode();
        }
    }
Read More

Observer Design Pattern in Jquery


We can use observer design pattern (publisher - subscriber model) in jquery by triggering and attaching events.
Attach a trigger event for publisher
$('div').on('click', function(e) {
    $(this).trigger('MyEvent',e,parameterValue);
});


Attach subscriber methods
$(document).on('MyEvent', function(e,parameterValue) {
    //Do your stuffs with parameterValues..
});
Read More

Monday, January 13, 2014

Overwrite Appsetting in ASP.NET MVC

  var config = WebConfigurationManager.OpenWebConfiguration("~");
  config.AppSettings.Settings["appSettingKey"].Value ="Updated value";
  config.Save(ConfigurationSaveMode.Minimal, false);
  ConfigurationManager.RefreshSection("appSettings");

Read More
Powered By Blogger · Designed By Seo Blogger Templates