EF6 Create one way navigation in db with two schemas - ef-code-first

We have two tables in the same database but in different schemas.
i.e. foo.Table1 and bar.Table1 both with an Id column as primary key.
foo.Table1 is from an existing model, cannot be modified and is already in the database.
We want to create an ef6 code first model of bar.Table1 that will have its primary key (bar.Table1.Id) set as a foreign key of foo.Table1.Id. We have already accomplished it in SMSS but we cannot figure out how to do it in code without affecting foo.Table1.
Thank you

Related

Reference another table in ASP.NET without a foreign key or joining tables

I have read-only access to a database. This database has multiple tables with status codes and one other reference table the gives a name for each code. These tables are not linked by a foreign key and I can't alter the database in any way. I'd like to display the status names in my web-app view instead of the numeric status code, is there a way to do this? Using EF Core 6
I tried to join the two tables but it didn't match the model in the View. I don't know how to remedy this situation without creating a new table (which I can't do)

Npgsql: Discrepency with Guids between Database.Migrate and Database.EnsureCreated

In a netstandard20 project, I'm using Npgsql.EntityFrameworkCore.PostgreSQL 3.1.0 and I'm having an issue using Guid as the type for my primary keys. If I use Database.EnsureCreated() to create the schema, the primary key columns get created with data type uuid. With everything the same except changing it to use Database.Migrate() creates all the primary key columns with data type text and then I get exception: Npgsql.PostgresException : 42883: operator does not exist: text = uuid when I try to perform any operations.
There is a single migration in my project to create the initial database. In that migration and also in the "context model snapshot" that are auto-generated, the primary key columns are all defined as Guid.
I need to both use the Database.Migrate() method to create the database and also have it create the Guid primary key columns as uuid. How can I make sure it creates the columns correctly?
I found this issue and response after posting my question. It led me to the correct answer which was that when I created the migration I was using sqlite. I needed to blow away the migration created against that data provider and regenerate it.

Can Sails.js attributes link to a collection via multiple columns?

I'm using Sails.js to build an API for an existing database. Unfortunately, modifying the structure of the database is not an option.
Many tables in the database have status columns of one type or another. They tend to have single-letter values that don't make sense without context. Context is provided by a "lookup" table in the database with 3 primary keys: table_name, column_name, and column_contents. Therefore, if I have a letter returned as a status, I can do a query against the lookup table and check a fourth column, description.
I'd love to configure my Sails.js models to understand all this, but it seems that one-to-many relationships can only be set up for tables with a single primary key. Is that correct?
Based on the "many-to-many" workaround, I assume the sails way to solve this would be to create new tables that are subsets of the "lookup" table (each for a single instance of table_name, column_name). Is there a better way?

asp.net Entity Framework/ Update from database/ The table/view does not have a primary key defined and no valid primary key could be inferred

One of the database view I am trying to import using entity framework contains only two columns, one is an integer type of column and another one is an aggregate function. I am getting the following error.
The table/view does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.
I understand it is a known scenario and it can be fixed by either including a Key column in the view or modifying the edmx file manually.
I just wanted to know if there is some other solution other than the above two? I do not want to include an additional column in my query and making changes in edmx is not feasible as DB changes are very frequent and the edmx will be overwritten every time I update from db.
You can mark both properties as entity key directly in the designer but you must ensure that the composite value of these two properties will be always unique. If you cannot ensure that you must add another unique column anyway or you may have some other problems when working with such entity set.

Update Data Model Business Entity

I have web application where Iam using linq to business entites i have business data model.
the problem is :
I have table with one column that it dosen't allow null value, when I try to update this table the folloeing error arise:
error The property 'e.g Carrier' is part of the object's key information and cannot be modified
what I can do?
The easiest thing to do is add a second column to the table that has a unique key eg guid and create a read only property on the entity that corresponds to it.
Linq to business entites needs some kind of key to keep track of what to update in the database. Usually this is the primary key on the database table. If you dont have a primary key it cannot reliably update the database and will then send you an exception.
Also if there is no primary key explicitly set on the table linq to business entites will select one of the columns (think its the first column in the table but i could be wrong) to act as a primary key and will therefore not allow you to update it.

Resources