<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
public class Employee
{
public string Id { get; set; }
public string Dept { get; set; }
public string Name { get; set; }
}
public class Role
{
public string Id { get; set; }
public string Right { get; set; }
}
public class JoinedTable
{
public string Id { get; set; }
public string Dept { get; set; }
public string Name { get; set; }
public string Right { get; set; }
}
protected void Page_Load(object sender, EventArgs erg)
{
if (!IsPostBack)
{
List<Employee> employees = new List<Employee>()
{
new Employee() { Id = "ID0001", Dept = "部署A", Name = "鈴木太郎" },
new Employee() { Id = "ID0002", Dept = "部署A", Name = "山田一郎" },
new Employee() { Id = "ID0003", Dept = "部署B", Name = "佐藤花子" }
};
List<Role> roles = new List<Role>()
{
new Role() { Id = "ID0001", Right ="〇" },
new Role() { Id = "ID0003", Right ="×" },
new Role() { Id = "ID0004", Right ="〇" }
};
var query = from e in employees
join r in roles on e.Id equals r.Id into gj
from sub in gj.DefaultIfEmpty()
select new JoinedTable
{
Id = e.Id,
Dept = e.Dept,
Name = e.Name,
Right = sub?.Right ?? string.Empty
};
GridView1.DataSource = query;
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html>
<script runat="server">
Public Class Employee
Public Property Id() As String
Get
Return m_Id
End Get
Set
m_Id = Value
End Set
End Property
Private m_Id As String
Public Property Dept() As String
Get
Return m_Dept
End Get
Set
m_Dept = Value
End Set
End Property
Private m_Dept As String
Public Property Name() As String
Get
Return m_Name
End Get
Set
m_Name = Value
End Set
End Property
Private m_Name As String
End Class
Public Class Role
Public Property Id() As String
Get
Return m_Id
End Get
Set
m_Id = Value
End Set
End Property
Private m_Id As String
Public Property Right() As String
Get
Return m_Right
End Get
Set
m_Right = Value
End Set
End Property
Private m_Right As String
End Class
Public Class JoinedTable
Public Property Id() As String
Get
Return m_Id
End Get
Set
m_Id = Value
End Set
End Property
Private m_Id As String
Public Property Dept() As String
Get
Return m_Dept
End Get
Set
m_Dept = Value
End Set
End Property
Private m_Dept As String
Public Property Name() As String
Get
Return m_Name
End Get
Set
m_Name = Value
End Set
End Property
Private m_Name As String
Public Property Right() As String
Get
Return m_Right
End Get
Set
m_Right = Value
End Set
End Property
Private m_Right As String
End Class
Protected Sub Page_Load(sender As Object, erg As EventArgs)
If Not IsPostBack Then
Dim employees As New List(Of Employee)() From {
New Employee() With {
.Id = "ID0001",
.Dept = "部署A",
.Name = "鈴木太郎"
},
New Employee() With {
.Id = "ID0002",
.Dept = "部署A",
.Name = "山田一郎"
},
New Employee() With {
.Id = "ID0003",
.Dept = "部署B",
.Name = "佐藤花子"
}
}
Dim roles As New List(Of Role)() From {
New Role() With {
.Id = "ID0001",
.Right = "〇"
},
New Role() With {
.Id = "ID0003",
.Right = "×"
},
New Role() With {
.Id = "ID0004",
.Right = "〇"
}
}
Dim query = From e In employees
Group Join r In roles
On e.Id Equals r.Id Into Group
From subrole In Group.DefaultIfEmpty()
Select New JoinedTable() With {
.Id = e.Id,
.Dept = e.Dept,
.Name = e.Name,
.Right = If(subrole Is Nothing, String.Empty, subrole.Right)
}
GridView1.DataSource = query
GridView1.DataBind()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</form>
</body>
</html>
先ほどのサンプルコードを変換サービスに投入してみたのですが、エラーになってしまいます。
エラーメッセージは以下でした。
CONVERSION ERROR: Code could not be converted. Details:
-- line 22 col 15: invalid TypeDecl
Please check for any errors in the original code and try again.
投入したのは<script runat="server">~</script>の間部分です。
どのように対応したらよいでしょうか?
Page_Loadの中だけでかけてもエラーになってしまいます。
sub.Rightに修正もしてありますが、エラー状況は変わりません。
CONVERSION ERROR: Code could not be converted. Details:
-- line 1 col 1: EOF expected
Please check for any errors in the original code and try again.
度々すみませんが、ご確認お願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/24 07:29 編集
退会済みユーザー
2017/11/24 08:11 編集
2017/11/24 08:11 編集
退会済みユーザー
2017/11/24 08:13
2017/11/24 08:30
退会済みユーザー
2017/11/24 08:52
2017/11/27 00:28