简体   繁体   中英

Database Question (LINQ-to-SQL)

I am currently working on a website where we can track small event for our clients. I am using linq-to-sql and asp.net to build it. So far the site is really small about 10 pages, and only 2 tables, events and clients. I have listed the columns for each table below:

Events:
-eventid
-eventname
-datecreated
-details
-datedue
-status
-clientname (this should be clientid)
-sentemail

Clients:
-clientid
-clientname
-clientemail
-clientphone

the issue I am having is getting the 2 database tables* to work together. Ideally I would like to have clientname replaced with clientid in the Events table.

I had it set up this way before but ran into an issue when listing out the events:

When I am listing out the events I would like it to show the client name as appose to the clientID. Unfortunately I am pretty new to ASP.net and although I could easily do it in PHP have no idea how to get it to work. Its not a huge deal but I would like to be able to update the client list and events apart from one another.

Sorry If this makes little to no sense, If there is any confusion I will try to word it better.

*correction on my part

数据库标准化后,创建一个Linq2Sql上下文,然后可以编写与此类似的查询(以获取事件名称及其客户端名称的列表):

var results = from e in dbContext.Events join c in dbContext.Clients on e.clientid equals c.clientid select new { e.eventname, c.clientname };

in addition to the answer of Andrew Lewis you need to:

1) add the clientid field to the events table

2) run a sql query to fill the clientid field:

update events set clientid = (select clientid from client where name = events.clientname)

3) remove the clientname field from the events table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM