Error 2062: no mapping between entity set and association set - entity-framework-4

Are entities required to be mapped to a table or can they map to a stored procedure?
I have an entity that does not map to any specific table, instead it maps to a stored procedure.
I am getting the following error:
Schema specified is not valid. Errors:
Model.msl(6,6) : error 2062: No
mapping specified for instances of the
EntitySet and AssociationSet in the
EntityContainer HNFS_ProviderEntities.

It appears to be yes: http://msdn.microsoft.com/en-us/library/bb896279.aspx
It turns out that instead of an entity I needed to use a complex type.

In my case I'd changed the name of the EDMX file and not updated the metadata within the connection string accordingly.
The Entity Framework designer seemed OK with this, however at runtime it'd throw Error 2062.
Referring to EDMXFILENAME in the below connection string example, make sure it is correct in all three places.
<add name="Entities" connectionString="metadata=res://*/EDMXFILENAME.csdl|res://*/EDMXFILENAME.ssdl|res://*/EDMXFILENAME.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVER;initial catalog=DATABASENAME;persist security info=True;user id=USER;password=PASSWORD;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

Related

SqlEntityConnection configured with a local schema file

I want to use the SqlEntityConnection type provider in f# to query and update a db.
It works well when I use it with the connection string pointing to a live SQL Server DataBase.
type EntityConnection = SqlEntityConnection<"Data Source=myServer;Initial Catalog=myDb;...", Pluralize=true>
Now I want to get rid of the dependency with the live DB and, instead, use a local schema file. Given what I read on msdn, I gave a try to the following line:
type private EntityConnection = SqlEntityConnection<LocalSchemaFile="mySchemaFile.ssdl", Pluralize=true>
Unfortunately, it doesn't compile and the compiler's message is:
Error 46 The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: When using this provider you must specify either a connection string or a connection string name. To specify a connection string, use SqlEntityConnection<"...connection string...">.
So what should I do? If I leave the connection string, I have the feeling that I don't really turn off the dependency to the DB. For instance, if I try to switch the Data Source with a non-existing server, it doesn't compile.
You can provide a connection string name, along with a connection string in the configuration file.
You can still provide a localschemafile that will be used to cache locally the schema.
If you put the schema file under source control, the connection string will only be used as a default when calling GetDataContext() without parameter, but not when building or editing code.
You also need to set the parameter ForceUpdate to False.

Breeze with second controller

I need to get some data from a different database (different server, actually), so I've created a second datacontext pointing to a second Breeze controller, repository, and edmx. I also created second model and entityManagerFactory since data I'll need to be getting is substantial and wanted to separate it from the base functionality. In my new EntityManagerFactory, if I have:
breeze.NamingConvention.none.setAsDefault();
all works well, but I don't get camel casing. If I have:
breeze.NamingConvention.camelCase.setAsDefault();
or if I don't call it at all (since it's just setting the app-wide default which is already set) I get this error:
[myDatacontext] [HT Error] Error retrieving dataMetadata query failed for: breeze/Vsp/Metadata. Unable to either parse or import metadata: NamingConvention for this server property name does not roundtrip properly:name-->Name; [object Object]Error: Metadata query failed for: breeze/Vsp/Metadata. Unable to either parse or import metadata: NamingConvention for this server property name does not roundtrip properly:name-->Name; [object Object]
There's not even a "name" or "Name" property on class I'm getting.
What am I missing?
By the way, I do get the metadata from the server. The client just doesn't like it.
I suppose that since you've posted this you found a solution.
But I also had this problem, it is because I use Entity-Framework ADO .Net 6.0, it takes into account stored procedure, views or tables that are not camelcase, so you have to unselect them before generating the model / context.

Error selecting from large data table causing time out in EF + code first

I am using EF code first model to get the data from data base table in which i have 400,000 records.
But when i use the LINQ query something like:
var urer = context.UserEntity.Where(c => c.FirstName.Contains('s'));
The above statement gives me all the user to whose first name contains 's'. But since this is a huge data base table, it is giving me the following error:
An existing connection was forcibly closed by the remote host
Please suggest me the best way to do it. I am assigning this data to gridview. I am thinking to get the first 500 each time. Is there any way to do it from EF side, so that i won't need to do it in sql.
Thanks
1.add index on your column
2. increase timeout connection
You can create Store procedure
USE LINQ call Store procedure
LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
See this answer as well
Calling a SQL Server stored procedure with linq service through c#
Get rid of EF
set key in web.config common key for timeout replace 600
try
{
conn.Open();
mySqlCommand.Connection = conn;
mySqlCommand.CommandTimeout=600;

Type provider: How to regenerate?

How would you make the LINQ-TO-SQL type provider, generate or/and regenerate the classes?
I've just added a new table to my database, and the type provider can't figure that out. I've tried to delete the line with the type provider, and type it once more - no luck. I've also tried to do a rebuild.. still no luck.
Edit:
I've defined the type provider like:
[<Generate>]
type dbSchema = SqlDataConnection<"conString">
and using it like:
let ctx = dbSchema.GetDataContext()
You're right - this seems to be quite tricky. I'm using SqlDataConnection type provider in a script file and the only way to update the schema that I've found so far is to make some minor (irrelevant) change in the connection string. For example, add space after = of one of the parameters:
[<Generate>]
type Northwind = TypeProviders.SqlDataConnection
<"data source=.\\sqlexpress;initial catalog=Northwind;integrated security=True">
[<Generate>]
type Northwind = TypeProviders.SqlDataConnection
<"data source=.\\sqlexpress;initial catalog=Northwind;integrated security= True">
// ^ here
The schema seems to be cached using connection string as the key, so if you change it back, you get the old schema again. I guess this is probably a bug, so adding whitespace is a possible workaround.
There is also a parameter ForceUpdate, but that doesn't seem to have any effect and the documentation doesn't say much about it.

Problem with SaveChange() in Entity Framework Data model

I am facing a problem with the SaveChanges() method in Entity Framework. Sometimes it works fine and sometimes it's not instead I get an error message saying:
String or binary data would be
truncated. The statement has been
terminated.
Can any one help me with this ....
thanks.
By default all strings stored as NVARCHAR(4000). In case while string length above 4000 chars you get this error. To limit field length and add validation logics to your model use StringLength(...maxlen...) attribute (http://msdn.microsoft.com/en-US/library/system.componentmodel.dataannotations.stringlengthattribute.aspx) with your model properties.
you can correct this problem on Data base Table on
"nvarchar" and "varchar Columns " that you increase Lenght of Column on your Table
also
when you insert or Update with EF , you can check len of value and check your query With
SQL Profiler when you call SaveChanges()method
and you check your value in GET and SET methods on Domain Layer or Entities that EF get you
and below link is Useful :
EF Exception: String or binary data would be truncated. The statement has been terminated.?
,
http://forums.asp.net/t/1660868.aspx/1

Resources