c#


Changing ntext to nvarchar using C# and Entity Framework


I have to add sorting to existing database created in SQL Server. The problem is that this database contains ntext columns that are not supported by LinQ's OrderBy method. The database was written in a code-first approach, so I have access to template of database, but I can't look at ready database working on the server.
I've tried to change string type properties marking them as
[Column(TypeName = "nvarchar(MAX)")]
but then I got a
Sequence contains no matching element
exception which I don't know how to fix.
This is the way that I wanted to sort my data(i got exception right in the below instruction:
MyDatabase.MyTable.OrderBy(x => x.MyRow).Load();
Before I changed TypeName to nvarchar, I've got this error:
Large objects (ntext and image) cannot be used in ORDER BY clauses
Can somebody help me with fixing things up to make possible to sort data from database?
I'll appreciate any kind of help. Thanks in advance!
In T-SQL you can solve this in many ways, may be you can adopt one of them for you too?
ORDER BY (cast MyTextCol as nvarchar(max))
create a view from
this table with that field casted as nvarchar(max) and use it
instead of your table(even in future)
ALTER TABLE myTable ALTER
COLUMN myTextCol nvarchar(max)
The last one solves your problem and takes no time to be made: it's just a metadata operation, nothing will reorganizen in your table for existing rows

Related Links

c# home works can't solve [closed]
generic class for linq / lambda expression
Access Denied Exception with Message Dialog
ArgumentNullException in Json.NET 6.0.7 when deserializing into NameValueCollection
log4net enabled, but not creating any files
C# Pause Program Execution
Carriage return in XElement
Selecting decimal and string anonymous types in single LINQ query that's grouped
C# Calling a method in non referenced project because of circular dependency
How to use an unassigned local variable for an abstract class object
Why am I getting “An object reference is required for the non-static field, method, or property 'Photrax.App.DBPath.get'”?
Change display name of foreign key MVC
WPF C# - The member “template” cannot be recognized or is not accessible?
Prevent Entity Framework recreating databases but use existing databases instead
The page was not displayed because the request entity is too large.When Download a 10Gb ZIP file
Unexpected termination of SSIS when calling it from a stored procedure initiated by a C# service

Categories

HOME
classification
internet-explorer
javafx
mobile
display
dronekit
gaussian
azure-resource-manager
lithium
pandoc
ubuntu-14.04
artifactory
sugarcrm
aggregation-framework
samsung-gear-s2
pyodbc
dcos
google-app-maker
runtime
spring-data-solr
core-data
decoding
guidewire
jetbrains
chef-recipe
vivado-hls
android-actionbar
aiml
autologin
project-structure
cherrypy
mattermost
procedural-generation
core-animation
mex
units-of-measurement
semantic-ui-react
folder
deferred
andengine
intermec
tikz
ibm-bpm
luhn
availability
flickr
android-geofence
oracle-bpm-suite
dotnetnuke-module
nscollectionview
socketcluster
directadmin
apiman
django-cors-headers
angular-fullstack
encoder
line-endings
stream-socket-client
react.rb
jscoverage
wink
playframework-2.3
node.js-client
tsc
lattice
stripes
toggleclass
alfred
qtruby
avaudiorecorder
laterjs
pebble-js
paypal-subscriptions
custom-build-step
video-embedding
ooad
tvp
serial-communication
nexusdb
cl.exe
disparity-mapping
rpt
msdropdown
step
sendy
class-library
nop
complete
pudb
magicsuggest
generator-expression
netbiscuits
event-propagation
github-archive
bash4
nsundomanager
hwnd
n2
response-time
nscharacterset
script-tag

Resources

Encrypt Message