I have been dealing with this for a couple weeks now, and figured it was time to bring someone else in. I have been to many sites trying to solve this, but I'll start from the beginning.
This is my first project in mvc and ef, so I have relied on a lot of tutorials.
I started with this one...
http://msdn.microsoft.com/en-us/data/gg699321.aspx
Everything else I find on the web pretty much just shows me the same things, so I figured this was pretty simple.
The stored procedure in question is pretty simple, it just returns a string from a table.
SELECT TOP 1 ConnectionString
FROM tConfig
WHERE Active = 1
I generated an edmx file, like in the article above, and it generated the following code in a context file. I have tried this both with, and without the EntityContainerName next to the procedure.
public virtual ObjectResult<string> psMasterDataSource()
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("CentralApp.psMasterDataSource");
}
Where I am using it is also pretty simple.
public string GetMasterDSConn() {
var context = new CentralApp();
var conn = context.psMasterDataSource().SingleOrDefault();
return conn;
}
But when I run it, I get the following error.
The FunctionImport 'psMasterDataSource' could not be found in the container 'CentralApp'.
I saw someone on another site talked about editing the XML, but I couldn't find anything helpful on what to edit. So I am hoping I am missing something simple there.
I appreciate any help on this. I am ready to get this app tested, but this is holding me back.
Related
Can anyone help me to understand what this error message (below) is trying to tell me?
I have code that successfully writes records to my SQL Server database table, and code that reads it back. But I've been struggling to create code to DELETE records from this same table.
An example of what I am trying to do:
public void DeleteUnfinishedTransaction(int uftID)
{
var uft = _dataContext.UnfinishedTransaction.Where(t => t.ID == uftID).FirstOrDefault();
if (uft != null)
{
_dataContext.UnfinishedTransaction.DeleteOnSubmit(uft);
}
_dataContext.SubmitChanges();
}
I've reworded this several different ways but when the "SubmitChanges" line is reached, this error is always thrown:
GenericArguments[2], 'System.Single', on
'System.Data.Linq.Mapping.PropertyAccessor+Accessor`3[T,V,V2]'
violates the constraint of type 'V2'.
I've been searching for information on this error to try to understand it and have been coming up empty-handed.
A little more info: this is a web application for which the 'metadata' (e.g., EDML, etc.) has been lost or destroyed, so all of the data access code which is normally auto-generated has to be written "by hand." I may have made a mistake somewhere else in the code -- the code above is just what triggers the actual error.
Any help understanding this would be greatly appreciated.
I struggled with this for days before posting a question here, but less than two hours after I did, I backed into the root of the problem.
In the code defining the structure of the fields in the 'UnfinishedTransaction' object (above), there were some unfortunate conversions being attempted between C#'s "single" and "double" data types, and SQL Server's "float." Once I fixed that I stopped getting the error and all appears well.
I'm surprised that those conversions were not problematic on 'Save' and 'Select,' only on 'Delete.'
I am writing a web service, using C# and Linq. I am fairly new to this, and using tutorials on line I have been able to do most everything I need. I have web services for a variety of complex operations on my database.
Where I have run into a problem is with adding records to my tables. I have followed a number of tutorials, which all seem very simple, but I have a reference that I am clearly missing and cannot find. I am using SQL Server (2008), and have built a WCF Service Library. The start of the code is:
public const int RET_OK = 0;
public const int RET_NOT_OK = -1;
public const int RET_TICKET_NO_SERVER = -1;
int retInt;
xxxxEntities3 xxxxDB = new xxxxEntities3();
public int CreateTicket(ref string strServer)
{
if ((strServer == null) || (strServer.Length == 0))
{
return(RET_TICKET_NO_SERVER);
}
ticket tick = new ticket();
tick.serveTime = DateTime.Now;
tick.server = strServer;
xxxxDB.tickets.AddObject(tick);
return (0);
}
I have made sure to add a reference to the System.Data.Linq assembly, and I have verified that the .edmx file is correct (all of my "reading" web services work great).
The problem is that when I try to insert changes (with something like this):
xxxxDB.tickets.SubmitChanges(tick);
I get that the SubmitChanges is not found (it asks if I am missing a reference). Am I? I am sure this is very simple, but I must be too tired - I just don't see it.
Thanks in advance!
Isn't SubmitChanged defined on at the root of the database layer? This is my experience with LinqToSql. For instance, you would manipulate things on a table by table basis, but push changes at once:
database.table.InsertOnSubmit(entity);
database.SubmitChanges();
Now, it looks like you're using a slightly different LinqToSomething mechanism that I'm not entirely familiar with - but many of the principles are not doubt shared.
As brought to attention by #Henk and #Kirk, there are a couple of things to consider here:
With EF, the call should apparently be on the context itself, as suggested
With EF, the call to make is SaveChanges as opposed to SubmitChanges
I'm having an odd little problem with MVC2. I am perorming some CRUD tasks, and I can Create records in the database just fine. But when I go to update a record with the following code nothing seems to happen to the database:
EntityModelConnection entityModelConnection = new EntityModelConnection ();
try {
OrderLogic orderLogic= new OrderLogic ();
EntityObject_Orders orderToUpdate = OrderLogic.GetOrderByID(1);
orderToUpdate.Name = "Laptop";
EntityModelConnection.SaveChanges(); }
My code isn't using names like these, they are just renamed for clarity :)
When I run over this code, no errors are thrown and the correct single record is returned from OrderLogic.GetOrdersByID, but nothing seems to update in the database.
It's a bit hard to find guides on this since most people are using UpdateModel in the controller and I'm doing my logic far from that location, so I can't (seem) to use that feature.
Any thoughts on what I might be missing? Is there something strange about MVC when it comes to updating records I might be missing?
I'm going for a coffee to refresh my brain :)
MVC or no MVC should have no effect on your data layer. I suspect that your order isn't being updated because it either isn't marked as being changed in the persistance layer or you're not getting it from the same persistance layer object that you're saving changes in. How is it that the connection you're creating and saving from is provided to the OrderLogic object to retrieve the EntityObject_Orders object?
It looks like your Order instance came from a different entity connection.
I have a dataset in a project which I'm using to provide databinding for winforms controls. Everything has been working fine (tableadapters with select, insert, update, delete methods provided by stored procedures) until I added another tableadapter this morning.
Since adding it, every tableadapter in the dataset broke. My project now has 63 errors reporting errors along the lines of :
Error 60 The type name 'SelectCompanyStatusesDataTable' does not exist in the type '..Search.Presentation.dsSearchTableAdapters.dsSearch' C:\Data\Visual Studio Projects\.\..Search.Presentation\dsSearch.Designer.cs 32210 33 ..Search.Presentation
(Using and to censor sensitive names)
I'm at a complete loss with regards to what has gone wrong, let alone how to fix it.
I'm wondering, has anyone seen anything like this happen before and maybe provide a few pointers for what direction I shoulod be looking in?
I know this is an old question but this just happened to me and I managed to fix all the compile errors by clearing out the MyDataSet.cs file (not the MyDataSet.Designer.cs file).
The MyDataSet.Designer.cs file has the following:
namespace MyNamespace {
[.....]
public partial class MyDataSet : global::System.Data.DataSet {
.
.
.
and the MyDataSet.cs file is usually empty (from looking at an old version). But for some reason (I think maybe double-clicking in the dataset designer while adding a new tableadapter), the MyDataSet.cs file had the following contents:
namespace MyNamespace.MyDataSetTableAdapters {
public partial class MyDataSet {
}
}
which, as you can see, doesn't match up with the definition in MyDataSet.Designers.cs.
Clearing MyDataSet.cs removed all the 'The type name 'MyDataTable' does not exist in the type MyNamespace.MyDataSetTableAdapters.MyDataSet' errors.
I know this is old but I found this by googling so hopefully it'll help someone else out!
I have only encountered this after an unsuccessful attempt to rename a dataset's namespace -- the namespace and classnames in the auto-generated and manually generated partial classes didn't match.
In the end I went for a scorched-earth policy and created a new dataset with a slightly different name, and used cut and paste to get the items of the designer in the original into the new dataset. I then deleted the original and updated all references to use the new one.
Thanks...this just happened to me as well.
I used the rightclick "rename" on the dataset.xsd to rename a datatable and adapter.
Blew everything away.
bummer....last couple hours gone.
Joe
It can happen if the connection string in the project settings changes, before a schema modification too. I know because it happened many times where I worked. I am an expert at fixing data-sets and also know some run-time work-rounds.
im using subsonic 3.0.0.3 activerecord and everything is fine and i get no error but when i update a database, it never seems to actually happen, can anyone spot anything i am missing here?! ta
code:
var myquote = createNewQuote();
var gross = 36.00;
myquote.totalcost = gross; // set the new value in my model
UpdateModel(myquote); // update the model, something to do with dirty columns??
if(ModelState.IsValid) // check to make sure i have no errors in my model after changing it
myquote.Update(); // command that is supposed to update the database????
i have put a break point on UpdateModel and looked into the model and the value is in the model as directed, i get no error and modelstate is valid too, but when i look into the database the totalcost has not actually been changed for that record????
i have also tried .Save() but this too does not seem to change anything ?????
am a little puzzled
not sure if this fixes your problem but I know there a few bugs fixed here that helped me out with a few isssues I was having.
Goto: http://github.com/subsonic/SubSonic-3.0/tree/master
There was a bug introduced in 3.0.0.1 that I removed quickly with 3.0.0.2 that inhibited updates in certain scenarios with ActiveRecord. Our current version is 3.0.0.3 - you should update.
Subsonic is not yet stable.. You will end up wasting your time googling around.. (peace!)
to solve your problem try this.
myquote.SetIsLoaded(true);