TagWith in Entity framework - c#

How to use TagWith() in entity framework 6.I read a lot of posts about TagWith() in the Entity Framework Core. but none of them provide information about entity framework not core
My main need is to add few comments to generated SQL query using EF.
var list = await _context.Tweets
.TagWith("GetTweets")<<---------------------------------------comment
.ToListAsync(cancellationToken)
.ConfigureAwait(false);

Related

how to add a new table to an existing db in web api c# entity core 2.14

I want to add a new table to an existing mdf db file.
The project is entity core version 2.14. (C# web api)
How can i add the table and update the model folder with the new entity
Any idea ?
This question is too general. Please take a look to documentation of EF core about migrations.
https://learn.microsoft.com/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli
Entity Framework Core is prepared for this kind of change.
To make it faster and easier I highly recommend you to use "EF Core Power Tools". Add your new table to your db directily using DB management tools. After this use Reverse Engineer option of the EF Core Power Tools to get a new EF code-first code.

.Net core 3.x Keyless Entity Types avoid table creation

I need to execute a complex sql query in entity framework core 3.1.1, on researching i found out that keyless entity types is the way to go in code first approach. I see lot of documents for dbquery but this is marked as obsolete in .net core 3.x
keyless entity types
As per Microsoft documentation it says dbquery is obsolete so use dbset approach instead, but with dbset it is trying to create a new table in database. how to disable table generation in keyless entity types while applying migrations?
Sample code
public class ApplicationContext : DbContext
{
public DbSet<CustomQuery> CustomQuery { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Ignore<CustomQuery>();
modelBuilder.Entity<CustomQuery>().HasNoKey();
}
}
with .net core 2.2
var entity = _context.Query<CustomQuery>().FromSqlRaw(Regex.Unescape(selectQuery)).AsNoTracking().FirstOrDefault();
with .net core 3.1
var newEntity = _context.CustomQuery.FromSqlRaw(Regex.Unescape(selectQuery)).AsNoTracking().FirstOrDefault();
if i try to apply migrations then a new table in the name of custom query is being created, but I don't need this to happen. because this is just an model used to hold the values from the join query and i will not insert, update or delete the values in this table. how to achieve this?
or is there any better approach for this situation.
This is a known defect in EF Core 3, reported here 3.0 Upgrade - Entity with HasNoKey() (formerly a query type) tries to create tables when adding migration #18116.
Closed as "duplicate" of To vs From methods: Proposal to rationalize ToTable, ToQuery, ToView, FromSql, and other related methods #17270 and Ability to exclude/skip/ignore parts of the model from migrations so that a table is not created (for overlapping bounded contexts) #2725, both scheduled for 5.0 release, which means it would eventually be addressed in that release.
The current workaround is mentioned in the comments by one of the EF Core team members:
For now, you can just use something like .ToView("You forgot to use FromSql with ModQueueEntry")
or more generally, using .ToView(null), e.g.
modelBuilder.Entity<CustomQuery>().HasNoKey().ToView(null);

How can I map my entity to a table in .Net Core project without using Entity Framework and only using ADO.NET

I have a project for Entities and I am using ADO.NET code for normal CRUD operations on this entity. I would like to map my entity name to table names, Could you please provide me a way to do it. With .Net Standard I could use System.Data.Linq.Mapping. But my project is in .Net Core 2.2 and I cannot add these as a reference, tried changing target framework, but my other projects are not compatible. Kindly advise me how do I do it.
I can see a couple of options.
1) Create a Mapper class that accepts T1 & T2.. And do the mapping manually for each property.
2) Use a library such as Automapper that does all this for you automatically (https://github.com/AutoMapper/AutoMapper)

EF class context

I have Microsoft VS 2010.In C# for retrieving data from database i use Ado.Net entity data model.This is Entity Framework?
I see in many articles that context created by Entity Framework is derived from dbContext but in my project context is derived form ObjectContext .
So, what is EF?
EF 4.0 (which is part of the .net Framework) uses System.Data.Entities.ObjectContext from EF 4.3 (which was Opensourced project and is not part of the Framework) onwards uses System.Data.Entities.DbContext.
Both are EntityFramework. One is newer. Both uses ADO.NET under the covers.
Yes, it is Entity Framework. However, context should be derived from ObjectContext. The ObjectSet
Represents a typed entity set that is used to perform create, read,
update, and delete operations.
and it was introduced in .NET 4.0
You may also take a look on this for additional information on object sets.

How do set up PostgreSQL + entity framweork?

The npgsql ado.net provider claims to support the entity framework.
Is there any documentation/guide how to set this up, and get me jump started here ?
Look at this stackoveflow question
Entity framework PostgreSQL
You may have more luck using NHibernate with NHibernate Linq with PostgreSQL

Categories

Resources