I have an MVC application using Entity Framework 4.1.
I am connecting to two different databases from this application, so I created two different .edmx files in my project. These edmx files have different container names and different namespaces. They both have a table with the same name (and same field definitions) that I want to use in my application.
When I add that entity into both models, my application will not compile. I recieve a "multiple definitions with identical signatures" error.
Do I have to rename the entities in order to accomplish this?
Thanks!
-Ben
EF doesn't support multiple classes with the same name in the same assembly regardless of what namespace those classes are in. You can use different names for the entities or separate them into separate assemblies.
Related
There is an extension for Yii2 I'm using, and it provides a database table and an ActiveRecord model class to work with entities in that table. My other models are generated with Giiant. I want to reference the library model from my generated models, e.g. so relation properties like $myEntity->thatLibraryEntity are generated correctly by Giiant. Is it possible to do so?
I haven't found a way to do so in the documentation, and in the source code the closest thing to what I want is setting the BatchController::$tableNameMap configuration parameter in Giiant, but that seems to only rename the models, and I would like to tell Giiant which existing ActiveRecord to use for entities in a particular table.
I worked around it.
The generated models reference class app\models\ThatLibraryEntity for table that_library_entity. I created that class, and made it extend the library ActiveRecord model I wanted to use.
Is there a way to use the class objects in a separate MS Access database without importing the class module and all its dependencies?
I have a database project that is fully running and I would like to use some of its' custom classes and data in a separate project. I would rather not have to import the class modules and their dependent queries as well as to link to their dependent tables.
No.
(This must be at least 30 chars, so here they are)
I am trying to implement a support for multiple database types in my project (mysql,mssql).
For now my main problem is migrations generation. As i understand i would need to separately generate a migration for each database type?
Is there any standard techniques that can be followed?
I see a number of posts talk about rolling your own LINQ to SQL XML mapping file. Why would you do this instead of using SQLMetal or the designer built into studio? Is it because you want to work with your own POCOs?
If you use the designer then you have no control over the generated classes. While this may be alright for many applications, it's not appropriate for all.
Probably the biggest single advantage to using an external mapping is that it breaks your model's dependency on Linq to SQL, so you could (for example) take the exact same model classes and use them with Entity Framework or NHibernate. Projects or assemblies which need to use the model don't pick up an unwanted dependency on the System.Data.Linq assembly.
Other things you might want to do are:
Include validation logic or other complex logic in property setters;
Use virtual properties (for proxying);
Decorate existing properties with other attributes (i.e. serialization);
etc.
None of these things are possible with generated code. You can extend via partial classes, but that only lets you add members, not change existing ones. You can change the designer-generated code, obviously, but your changes will just get overwritten.
As I mentioned, many projects don't need these things, but many projects do, and if yours is one that does then you'll outgrow the DBML designer and SqlMetal pretty quickly.
In the NerdDinner example they use a repository pattern to decouple the business from the data layer. But then they use the Linq to SQL generated classes (Dinner specifically) as the entity class used throughout the project. So how decoupled is that really? It’s not like you could easily exchange Linq-to-SQL.
On my last project I created a separate entity class that I populated with left/right in the linq query because I found that even if you use a partial of the linq generated you cannot populate any additional fields that you add at query time.
LINQ to SQL is strongly tied to the database schema, which is why I wouldn't use it. I'd use Entity Framework instead, as it permits a mapping between the conceptual and logical models.