Advertisements

Archive

Author Archive

How to fix function is ambiguous in the namespace ‘system’ compiler error


When you are upgrading your project framework its possible that old version of DLL reference still exists , to remove that follow the below steps

-Open Object Explorer in Visual Studio
-Find that function
-Find the function/dll which has old reference and delete it

Hope it helps!

Advertisements
Categories: ASP.NET

Call Repeater ItemCommand event manually from outside the repeater

February 6, 2018 Leave a comment

Following is the code to call repeater item command event manually

Private Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click

For i = 0 To rptPlayers.Items.Count – 1

Dim tItem As RepeaterItem = rptPlayers.Items(i)

Dim tButton As ImageButton = ptPlayers.Items(i).FindControl(“imgAdd”)

Dim tEvents As New System.Web.UI.WebControls.CommandEventArgs(tButton.CommandName, tButton.CommandArgument)

Dim rpt As New RepeaterCommandEventArgs(tItem, tButton, tEvents)

rptPlayers_ItemCommand(tButton, rpt)

Next

End Sub

Categories: ASP.NET

Telerik ORM : Row not found: GenericOID@ OptimisticVerificationException

January 12, 2018 Leave a comment

This kind of error occurred When DataAccess tries to update the row in the database which has the original values for the fields that have changed.

The reason the update fails is that the artificial columns added at runtime are nullable but the CLR property which these columns are mapped to are all non-nullable. Ex – bit column is mapped to Boolean CLR property.

The generated UPDATE statement tries to find a row with the CLR default value i.e 0 but the value in the column is NULL.

I have updated the method that maps the artificial properties as follows –

var propType = Type.GetType(property.PropertyType);
if(propType.IsValueType)
{
propType = GetNullableType(propType);
}
var primitivePropertyConfiguration = myConfig.HasArtificialPrimitiveProperty(property.PropertyName,propType).HasFieldName(property.PropertyName);

Here I check if the Type of the field is a value type and if it is, then I create a nullable CLR type instead of the non-nullable type.

The helper method used is as below

public static Type GetNullableType(Type type)
{
if (type.IsValueType)
{
Type nullable = typeof(Nullable);
return nullable.MakeGenericType(new[] { type });
}
return type;
}

Hope this help !

Categories: ASP.NET

EXT.NET : Getting selected RadioGroup value through inputValue

January 11, 2018 Leave a comment

How to get selected value from RadioGroup in EXT.NET

Consider following sample code

On the server side I would like to be able to do something similar to this:

var value = typeRadioGroup.CheckedItems[0].InputValue;

to get the selected value directly and proceed with the code instead of calling e.g.

if (dailyRadio.Checked)
// do something
else if (weeklyRadioChecked)
// something else

Hope This help !

Categories: Ext.NEt, Tips & Tricks Tags: ,

Data Annotations – ForeignKey Attribute in EF 6 & EF Core

January 7, 2018 Leave a comment

The ForeignKey attribute is used to configure a foreign key in the relationship between two entities in EF 6 and EF Core. It overrides the default conventions. As per the default convention, EF makes a property as foreign key property when its name matches with the primary key property of a related entity.

ForeignKey Signature: [ForeignKey(name string)]

  • name: Name of the associated navigation property or the name of the associated foreign key(s).

Consider the following example of one-to-many relationship among entities.

public class Student
{
    public int StudentID { get; set; }
    public string StudentName { get; set; }
        
    //Foreign key for Standard
    public int StandardId { get; set; }
    public Standard Standard { get; set; }
}

public class Standard
{
    public int StandardId { get; set; }
    public string StandardName { get; set; }
    
    public ICollection<Student> Students { get; set; }
}

The above example depicts a one-to-many relationship between Student and Standard entities. To represent this relationship, the Student class includes a property StandardId with reference property Standard and Standard entity class includes collection navigation property Students. A property name StandardId in Student entity matches with the primary key property of Standard entity, so StandardIdin Student entity will automatically become a foreign key property and corresponding column in the db table will also be a foreign key column as shown below.

Entity Framework code-first example

The [ForeignKey] attribute overrides the default convention for a foreign key It allows us to specify the foreign key property in the dependent entity whose name does not match with the primary key property of the principal entity.

The [ForeignKey(name)] attribute can be applied in three ways:

  1. [ForeignKey(NavigationPropertyName)] on the foreign key scalar property in the dependent entity
  2. [ForeignKey(ForeignKeyPropertyName)] on the related reference navigation property in the dependent entity
  3. [ForeignKey(ForeignKeyPropertyName)] on the navigation property in the principal entity

[ForeignKey] on the foreign key property in the dependent entity:

The [ForeignKey] on the foreign key property in the dependent entity and the related navigation property name can be specified as a parameter as shown below.

public class Student
{
    public int StudentID { get; set; }
    public string StudentName { get; set; }
        
    [ForeignKey("Standard")]
    public int StandardRefId { get; set; }
    public Standard Standard { get; set; }
}

public class Standard
{
    public int StandardId { get; set; }
    public string StandardName { get; set; }
    
    public ICollection<Student> Students { get; set; }
}

In the above example, the [ForeignKey] attribute is applied on the StandardRefId and specified the name of the navigation property Standard. This will create the foreign key column named StandardRefId in the Students table, preventing the generation of a StandardId column in the database.

Entity Framework code-first example

[ForeignKey] on the navigation property in the dependent entity:

The [ForeignKey] attribute can be applied to the navigation property and the related foreign key property name can be specified as shown below.

public class Student
{
    public int StudentID { get; set; }
    public string StudentName { get; set; }
        
    public int StandardRefId { get; set; }
    
    [ForeignKey("StandardRefId")]
    public Standard Standard { get; set; }
}

public class Standard
{
    public int StandardId { get; set; }
    public string StandardName { get; set; }
    
    public ICollection<Student> Students { get; set; }
}

In the above example, the [ForeignKey] attribute is applied on the Standard navigation property and specified the name of the foreign key property StandardRefId. This will create the foreign key column named StandardRefId in the Students table, preventing the generation of a StandardId column in the database.

[ForeignKey] on the navigation property in the principal entity:

The [ForeignKey] attribute can be applied to the navigation property in the principal entity and the related foreign key property name can be specified in the dependent entity as shown below.

public class Student
{
    public int StudentID { get; set; }
    public string StudentName { get; set; }
        
    public int StandardRefId { get; set; }
    public Standard Standard { get; set; }
}

public class Standard
{
    public int StandardId { get; set; }
    public string StandardName { get; set; }
    
    [ForeignKey("StandardRefId")]
    public ICollection<Student> Students { get; set; }
}

In the above example, the [ForeignKey] attribute is applied on the Students navigation property in the principal entity Standard. This will create a foreign key column StandardRefId in the Students table in the database.

Hope this help !

Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping For jQuery in .Net

December 18, 2017 Leave a comment

Getting below error after using RequiredFieldValidator for textbox

Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping For jQuery in .Net

In this post I am trying to explain solution for the above error.

Sample Code :

<asp:TextBox ID=”txtName” runat=”server”></asp:TextBox>
<asp:RequiredFieldValidator ID=”reqName” runat=”server” Display=”Dynamic” ControlToValidate=”txtName”  Text=”*” Style=”color: red”></asp:RequiredFieldValidator>
<asp:Button ID=”btnSubmit” Text=”Submit” runat=”server” OnClick=”btnSubmit_Click” />

Solution

Now add key for Unobtrusive under web.config file <appSettings> tag as following code.

 

<configuration>
<system.web>
<compilation debug=”true” targetFramework=”4.5″ />
<httpRuntime targetFramework=”4.5″ />
</system.web>
<appSettings>
    <add key=”ValidationSettings:UnobtrusiveValidationMode” value=”None” />
</appSettings>
</configuration>

 

 

Entity Framework : Could not load type System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider

December 8, 2017 1 comment

When you have separate class library projects for Data access layer which contains your entity model and when you are giving reference of this class library to your web application on build you may get following error

Could not load type System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider

You can solve this error by following line assembly reference in your website project webconfig file

<system.web>
    <compilation debug="true" targetFramework="4.5">
        <assemblies>
            <add
                assembly="System.Data.Entity.Design, Version=4.0.0.0,Culture=neutral,
                PublicKeyToken=B77A5C561934E089" />
        </assemblies>
    </compilation> 
    <httpRuntime targetFramework="4.5" />
</system.web>