Playing with date time in both dotnet and sql server (t-sql) is always challenging and painful for me. Sometimes I forget that, entity framework cannot translate expressions into sql if I convert type using Convert class. like, Convert.ToDateTime(). If I do so then entity framework throws error like:
"The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. "
To rescue from this, Microsoft introduces DbFunctions class from EF6 version. Prior of EF6 it was EntityFunctions. There are lot of built-in functions related to datetime type has been implemented there. Check them out.
...What's New?
ASP.NET, C#, JQuery, CSS, HTML, SQL Server
Thursday, March 16, 2017
Saturday, January 28, 2017
Right Way for Editing EDMX File of Entity Framework (EF)
As an object relation mapper, Entity Framework enables user(in this case, developer) to work with relational data in object oriented manner. It helps user to do operations like insert, update, delete, search - in database without writing sql like string and getting help of intelligence of code editor like visual studio.
Updating Entity Framework from database could be hassle if user do not know where to do what. As for example, to update a stored procedure follow the following steps -
1. Open edmx file.
2. Right click and select Model Browser
Delete stored procedure
3. from Complex Type (if any)
4. from Function Imports
5. from Stored Procedure / Functions
Then save, then update from database.
If the Stored Procedure is complex type, that means, it is returning some rows (like table) then follow these steps -
1. Write these two lines at the beginning -
SET NOCOUNT ON
SET FMTONLY OFF
2. Use temporary table to store data and finally return that table.
IF OBJECT_ID('tempdb..##PGM_MonthlySalaryStatement') IS NOT NULL
BEGIN
DROP TABLE ##PGM_MonthlySalaryStatement
END
..........
..........
INSERT INTO ##PGM_MonthlySalaryStatement
..........
..........
SELECT * FROM ##PGM_MonthlySalaryStatement
Thats it.
Happy coding
Updating Entity Framework from database could be hassle if user do not know where to do what. As for example, to update a stored procedure follow the following steps -
1. Open edmx file.
2. Right click and select Model Browser
Delete stored procedure
3. from Complex Type (if any)
4. from Function Imports
5. from Stored Procedure / Functions
Then save, then update from database.
If the Stored Procedure is complex type, that means, it is returning some rows (like table) then follow these steps -
1. Write these two lines at the beginning -
SET NOCOUNT ON
SET FMTONLY OFF
2. Use temporary table to store data and finally return that table.
IF OBJECT_ID('tempdb..##PGM_MonthlySalaryStatement') IS NOT NULL
BEGIN
DROP TABLE ##PGM_MonthlySalaryStatement
END
..........
..........
INSERT INTO ##PGM_MonthlySalaryStatement
..........
..........
SELECT * FROM ##PGM_MonthlySalaryStatement
Thats it.
Happy coding
Thursday, June 23, 2016
Channel 9 usefull tutorials
Some channel 9 good tutorials:-
Creating Virtual and Augmented Reality Applications on Windows Platform
Creating Virtual and Augmented Reality Applications on Windows Platform
Developer Productivity: What's New in C# 6
Twenty C# Questions Explained
Security Fundamentals
Game Development:-
Construct 2 Advanced Game Development
Developing Advanced 2D Games with HTML5
Twenty C# Questions Explained
Security Fundamentals
Game Development:-
Construct 2 Advanced Game Development
Developing Advanced 2D Games with HTML5
SQL Server DB:-
Application Performance Monitoring
What's New with ASP.NET 5
Customizing ASP.NET Authentication with Identity
Web API Design
Cross-Platform Development with Xamarin & Visual Studio
Lighting Up Real-Time Web Communications with SignalR
Cross-Platform Development with Xamarin & Visual Studio
Lighting Up Real-Time Web Communications with SignalR
MVC:-
PowerShell:-
Advanced Tools & Scripting with PowerShell 3.0
Advanced PowerShell Techniques
Getting Started with PowerShell 3.0
TFS and Git:-
Software Testing:-
JavaScript:-
Introduction to jQuery
JavaScript Fundamentals: Development for Absolute Beginners
HTML5 & CSS3 Fundamentals: Development for Absolute Beginners
JavaScript Fundamentals: Development for Absolute Beginners
HTML5 & CSS3 Fundamentals: Development for Absolute Beginners
Miscellaneous:-
Microsoft Campus Tours
Do More With Your Microsoft Lumia Phone
A Developer's Guide to Windows 10
Visual Studio 2015 Enterprise Videos
Visual Studio TV
Thursday, February 18, 2016
EF error - Type '{your_entity_name}' already defines a member called '.ctor' with the same parameter types
Couple of days ago I have decided to set custom database connection string to my entity framework data model in one of my project. Then I have created a partial class with the same name of my entity and modify connection string name of base parameter. like example below -
public partial class DBPointOfSalesEntities
{
public DBPointOfSalesEntities()
: base(my.GetEntityConnectionString)
{
}
}
and deleted default constructor from [model].cs file.
But the problem is, whenever I update my model, it generates default constructor with default base parameter value. And occurs error for ambiguous constructor name as I have created above.
Then after googling, I found a nice solution - there is a [model].tt file which is called T4 template. Entity model is generating its automatic code based on this template. There is a specific code snippet which is responsible for generating default constructor after updating model from database each time. following is that code snippet. I have just deleted those lines and my problem fixed.public <#=code.Escape(container)#>()
: base("name=<#=container.Name#>")
{
<#
if (!loader.IsLazyLoadingEnabled(container))
{
#>
this.Configuration.LazyLoadingEnabled = false;
<#
}
foreach (var entitySet in container.BaseEntitySets.OfType())
{
// Note: the DbSet members are defined below such that the getter and
// setter always have the same accessibility as the DbSet definition
if (Accessibility.ForReadOnlyProperty(entitySet) != "public")
{
#>
<#=codeStringGenerator.DbSetInitializer(entitySet)#>
<#
}
}
#>
}
Happy coding...
Wednesday, January 13, 2016
Using "Crystal Report" with "Visual Studio 2010"
First shocking news is Crystal Report tool is not included by default with Visual Studio 2010. To come back from this shock, download crystal report tool from following link
=> http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0.exe
After install don't forget to restart your computer. Because this is WINDOWS. Then after creating your first report if you get the following exception -
Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies.
Than open App.Config file. Then find the attribute useLegacyV2RuntimeActivationPolicy and change the value to "true"
Happy Coding..........
Subscribe to:
Posts (Atom)