How to use Linq-to-SQL without having to generate all classes?

I have never used Linq-to-Sql before in an application, but I used LinqPad to develop a query and just wanted to insert it into my code.

It's not so easy. I figured out what I needed DataContextto handle the connection, but I still get errors because the view names are not recognized.

Should I use the constructor and create all View / Table classes? Is there an easier way?

This is a request. No updates are needed - just this request ....

var q = from user in V020
    join userapp in V010 on user.SPP_USER_ID equals userapp.SPP_USER_ID
    join app in V030 on userapp.SPP_AW_ID equals app.SPP_AW_ID
    join tx in V040 on app.SPP_AW_ID equals tx.SPP_AW_ID
    join appber in V070 on app.SPP_AW_ID equals appber.SPP_AW_ID
    join ber in V050 on appber.SPP_AW_BEREICH_ID equals ber.SPP_AW_BEREICH_ID 

    where app.SPP_AW_AKTIV && user.SPP_USER_ID == "userid" && tx.SPP_AW_SPR == "de" && ber.SPP_AW_SPR == "de"

    orderby ber.SPP_BER_SORTNB

    select new {
        AppName = app.SPP_AW_KURZBEZ, Url = tx.SPP_AW_URL, Label = tx.SPP_AW_NAME, Description = tx.SPP_AW_BESCHR,
        Bereich = ber.SPP_AW_BERNAME,
        Owner = app.SPP_AW_VERANTW, Remote = app.SPP_AW_REMOTE
    }

    ;
+3
source share
2 answers

Add dbml file

  • Create the dbml file as above
  • Open Server Explorer
  • Connect to your database
  • , ,
+1

EF context.Database.ExecuteSQLCommand (, , ). , - Linq to SQL. linq, . .

SiteManagedRepairDetails:

 public long RepairID { get; set; }
 public int RepairLineID { get; set; }

DAL:

public static int UpsertData(SiteManagedRepairDetails obj)
        {

            XYZ.DBContexts.VoidsDBContext context = new XYZ.DBContexts.VoidsDBContext();
            var results = context.Database.ExecuteSqlCommand("p_XYZDetailsUpsert @RepairID, @RepairLineID"
                , new SqlParameter("@RepairID", obj.RepairID)
                , new SqlParameter("@RepairLineID", obj.RepairLineID)
            );
            return 0;
        }
0

All Articles