I'm working on an MVC site using EF4 as my data source. I've had no problems with other projects with EF4 until today. I'm getting an error stating EntitySet name Entities.Sites could not be found. I have another EDMX file for another dataset that is set up nearly the same (with different entity names) and it works fine when I try to run a LINQ query against it.
My EDMX has 2 tables (site and page) with a 1 to many association from the site to page table. Everything compiles fine, but in runtime, it's almost like the datamodel fails on every property list population. I do have Lazy Loading enabled (It's a .NET 4 project).
I stepped through the code on the designer class and it fails when it gets to a call like this
if((_Pages == null))
{
_Pages = base.CreateObjectSet<Page>("Pages");
}
I have not altered the code in the designer.cs. I'm at a major wall with this.
Any ideas what I could be doing wrong?
Try renaming your entity Page to something else, like EntityPage (for example) to see if this resolved it. As stated by #Yakimych this could simply be a case of Namespace clashing
Related
I recently upgraded a relatively old System TYPO3 4.7 => 6.2.
I changed alot of namespaces/imports etc. and fixed stuff here and there. After the system was stable I made some changes in the extension builder and added some new fields.
I had to change some code in some files that threw errors but after that I was able to successfully save in the extension builder.
It added the correct classes,attributes and actions but now the system shows me this error:
1247602160: Table 'keepins_upgrade.tx_extbase_persistence_objectstorage' doesn't exist
Usually this error is related to models that are mapped incorrectly in the typoscript file but this seems different.. any suggestions?
Shot from the hip: you have one or more properties in your domain model which is annotated incorrectly - so it is read as a 1:1 relation to ObjectStorage, not a 1:n to a collection of another object. Or, less likely given your previous version, you've annotated a setter method or controller action so it requires an instance of ObjectStorage, but neglected to add PHPDOC that defines the true expected child type or is somehow else invalid or not connected to the right property.
I just upgraded to EF6 from EF5 and I encounter this error in a custom T4 that connects to the DB using a DbContext from a different assembly.
File: EF6.Utility.CS.ttinclude
Compiling transformation: The name 'ArgumentNotNull' does not exist in the current context
What I've done is replacing EF.Utility.CS.ttinclude with EF6.Utility.CS.ttinclude, which solved another error about DbSet and DbContext not being found.
The T4 is very simple, like this one:
using(var context = new EntityContext)
return context.Entities.Where(x => 1==1);
Except for the EF include I only reference my own assemblies. The freshly-added Context is generating just fine (in another project).
What on earth could be wrong?
EF6.Utility.CS.ttinclude reference some static functions that are defined in the main template.tt so you need to have them in your template too.
Example:
Entity.tt defines ArgumentNotNull(T arg, string name) which is used in the EF6.Utility.CS.ttinclude (it's not the way we are used to have)
See the bottom of generated template from EF6 designer to see this missing functions
One way to solve this is moving almost all the code to a .cs file and then use that file in the T4 template. Then remove the EF ttinclude from the T4 template.
Works and is easy better praxis to follow.
Just started using VS 2012 and I generated an EF Model from the database. All worked fine, although in my previous experience I had to put a using in my code.
I tried to set up a .cs file with partial classes to provide custom business logic behaviors to the generated classes and Intellisense does not recognize ar prompt with the generated classes.
I did as others have stated and brought up the properties panel of the Edmx model and fount the namespace. However, when I try to put it in a using statement, Intellisense does not recognize it.
Am I missing something here? EF can get very confusing and frustrating if one goes more than an inch or so below its generated surface.
Turns out that EF5 generates a model such that you do not need to have a "using namespace;" or a "namespace xxx"{} in the code file.
Just a simple xxx.cs file and each partial class definition you want to make:
public partial class MyClass
{
}
I'm trying to run codeanalysis on an assembly that contains an entity model (edmx file). In project properties I have checked the "Suppress results from generated code" option, but I am still getting a lot of CA errors pertaining to the auto-generated EF code.
Has anyone experienced this? And is there a work-around?
Just put the attribute on your class definition.
But how to do it, since your file can get overridden any time. Use a separate file, since all generated classes are partial classes. Open a separate file, and write something like:
[GeneratedCode("EntityModelCodeGenerator", "4.0.0.0")]
public partial class YourEntitiesContextName : ObjectContext
{
}
This will skip code analysis on your particular generated class. StyleCop for instance is more smart and doesn't touch files that have .designer/.generated part in their name or regions that have generated word in their name.
Well, "Suppress results from generated code" really means "Don't look at types with GeneratedCodeAttribute". EF's code generator hasn't added this, historically (though I've suggested it to the team). But you can add it if you use custom T4.
Having created a standard Silverlight Business Application in VS2010 and set up a model from a SQL Server database, I have various entities and associations, among which AssetGroup and Asset are in a 1:m relationship.
Allegedly I can use dot notation to get the associated AssetGroup out of an asset instance. Through the modern miracles of deferred execution and lazy loading, I am assured, my data will be delivered the very moment that I need it.
But it doesn't work.
What are the required incantations, and do I have to slay a chicken or a goat?
This looks promising. As soon as I've tried it out I'll update.
In the question I mention a blog post containing a possible solution. That solution works, but entails changes to generated code, which is obviously as fragile as a solution gets.
Here's a robust way to apply the solution: change the code generator.
On the EDMX designer surface right-click for the context menu and choose Add Code Generation Items...
Try to improve on "Model1.tt" as a name and save the TT file.
Open the TT file.
Search for "return (" to directly find the method template you need to change.
Edit as shown.
Rebuild the solution.
Change this
return /* big hairy expression */;
to this
var entity = /* big hairy expression */;
if (!entity.IsLoaded) entity.Load();
return entity;