The data reader is incompatible with the specified... A member of the type, 'Finalised', does not have a corresponding column in the data reader - visual-studio-2010

I have added a column in my Sql Server Db then in VS i updated model from database, there a template auto generated some code.
The code compiled fine, but when i try access a the data base, the following error occurs:
The data reader is incompatible with the specified
'CompassModel.tbSalesContract'. A member of the type, 'Finalised',
does not have a corresponding column in the data reader with the same
name.
Finalised is the new column i added to my database.
Does anyone know how to track this down, and if so, is there a fix or methodology to follow to avoid in the future?

If you are using a SP then update the newly added column in that Or If you are using inline query put the exact name of the newly added column . The template you are talking about does not contain the newly added column name ..Try to edit the template ..the issue will be resolved.

If you are using a SP, then please make sure the alias names used.. ie. for eg: It should be written as
fieldname as 'aliasname'
thanks,
criss thomas

Hopefully this helps someone out but when I received this error I was trying to return an entity type from a stored procedure.
To fix this I had to add the correct function import mapping. In your edmx go to the Model Browser view and navigate to Funtion Imports. Right click your sproc name and select function import mapping. There you can map your sproc return results to the appropriate entity property.

Related

Laravel Migration - Data type also changes when renaming column

I want to rename the column in database using migration, but when i tried it, the datatype also changes. How to rename column without changing the data type.
The current name of the column in the database is
payment_amount_cash and its type is double(10,2)
I tried
$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
to rename the column. Then after migration, the name was changed but the data type was also changed from double(10,2) to only double thus, making the default value change from 0.00 to 0.
I also tried to change the data type after the schema of renaming the column.
$table->renameColumn('payment_amount_cash', 'payment_amount_full')->comment('Advanced payment')->default("0.00");
$table->double('payment_amount_full', 10,2)->change();
but this one gives me error upon migration.
Doctrine\DBAL\DBALException : Unknown column type "double" requested.
Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType().
You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap().
If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type.
Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes().
If the type name is empty you might have a problem with the cache or forgot some mapping information.
With this, I just want to know how to rename the column without affecting the data type. After migration, I would like to retain the data type of the column I just changed the name.
I learned that there is an issue in Schema regarding the enum and still in discussion until now.
I just used the other way to update the datatype of the column.
DB::statement('ALTER TABLE reservations MODIFY COLUMN payment_amount_full double(10,2)');
and this works for me. If there are other ways on how to do this, please let me know. Thanks.

Servicenow - Service Catalog Reference Field - Insert different column than the display value

Let me describe my problem:
I have a table for all my IT-Services. I reference to this table more than once, for different purposes. Most of the time I need to reference to the name of the service. That's why I keep the name as displayed value.
One Column of that table is a service_id (custom field) which is for example "Service_004". Now in a catalog request Item the User has to fill in the service_id in a reference field.
But since I have the name as displayed value, and I need it in other forms, I am unable to reference to the service_id.
Using the variable attributes field I managed to let the service be found using the autocomplete function. But in the reference field I still get the servicename. I know that I can change the display value in the dictionary, but this breaks other functions. So what I need is to change the display value just for one reference field.
Also I tried to create a new table called IT-Services2 with reference to my table IT-Services. Then I switched the display to true in the new table for my service_id, but this will even change it in the parent table.
Perhaps an onChange client script utilizing g_form.setLabelOf() ?
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#setLabelOf
Maybe I'm not fully understanding your question...
I ran into this issue before, what you can do is create select box variable and use an on load client script to populate the list with the service_id(s) from the table you are referencing.
I would write a script include to pull the data from the table and call it from the client script via GlideAjax.

Changed existing entity model and manually updated SQL Server database but still get context changed error

I have an existing MVC3 application and database that is on a SQL Server 2008 R2 and I had to add a bool item to an existing model.
After I added it to the model, I rebuilt and published the project. Then I opened up SQL Server Management Studio and went to the table and added the entry to the column as a bit, I had to make it nullable since the table already contains data.
I thought this would be all that I would need to do to get everything working. However I got this error:
The model backing the 'psllc_DB' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
I'm not sure what else to do, I went back to the code and changed the bool to bool? so it will be nullable but this didn't help either. I can't drop the entire database since it's full of data, however as a last ditch possibility I could drop this table and re-create it cause it only has a few entries, but I don't know if that will work. I'm not sure what else to do so any advice would be very appreciated.
Update
Since I'm not getting any responses, let me rephrase my question.
How should I update my database (a SQL Express mdf file) to add a bool Column to a Table that has data already? I need the database to match my updated MVC 3 Entity Code First model otherwise I get the above error.
Thanks
Since this is code-first, you should do this code-first: change the class and use EF-migrations to change the database. The way you do it, the model and the database may match, but the meta information in the database is not updated.
By the way, if you supply a default value, you can add a non-nullable column.

MVC Linq to SQL Update Object in database

I have a table called Code in my LINQ to SQL datacontext. I also have a class called Codes in my Models folder. What I want to do is save the updated object Codes to my database table Code. Is this possible?
In my controller, I would pass the edited Object to my Model. My CodesRepository file contains this:
public Codes EditCode(Codes CodeToEdit)
{
private EventsDataContext _db = new EventsDataContext();
Codes C = new Codes();
C = CodeToEdit;
_db.Codes.InsertOnSubmit(C); //error here, something about invalid arguments
//InsertOnSubmit is for adding a new object, but I don't know the syntax
// for editing an existing object.
_db.SubmitChanges();
}
This is probably not the correct way of doing this so can someone point me in the right direction? Do I even need a class called Codes or do I need to somehow just use my database table? Thanks.
Solution: I decided to change from Linq to SQL to an Entity Framework and it works much better. This way, I don't have to define my Codes class since it comes straight from the database and I was able to delete the Codes class file.
You should use DataContext.Attach when you get an object back that corresponds to en existing row in the database. For Linq-to-sql's optimistic concurrency handling to work this requires that you either have the original, unsaved object available, or that you have a TimeStamp column in the database. The latter is preferred, as it only requires one extra field to be handled (probably through a hidden field in the web form).

Devart InsertAllOnSubmit doesn't update db generated fields

I'm using Devart's Linq to Oracle components. I've got a table with a field that's updated via a sequence in the database. This works fine when inserting one row:
Dim db As New DataContext
db.MyObjects.InsertOnSubmit(MyObject)
db.SubmitChanges()
At this point, MyObject.Version will contain the version identifier that was generated in the database. So I was expecting that this code would work fine:
Dim db As New DataContext
db.MyObjects.InsertAllOnSubmit(MyObjectsList)
db.SubmitChanges()
But when I do this, the Version field is unchanged in all of the objects in MyObjectsList, even though the rows are being added to the table.
What am I missing here? Thanks in advance.
For the database-generated value of an entity member to be retrieved when this entity is inserted, one of the following should be true:
the 'Auto Generated Value' property of this member is set to true;
the 'Auto-Sync' property of this member is set to 'OnInsert' or
'Always'.
Please check that either of these conditions is satisfied. Also, please try updating to the 6.30.160 version of dotConnect for Oracle (if you are using a prior build).
If the problem persists, could you please send us a test project with which it can be reproduced?
Well, I found the problem and it had nothing to do with devart. The problem turned out to be that I was passing an IEnumerable(Of MyObject) to the method, which was the result of another query. When I materialized this list to a List(Of MyObject) and passed that instead, the db generated fields did appear in my objects. I must admit I don't quite understand why this mattered, but at any rate it fixed the problem. Hope this helps someone else some time

Resources