Skip to content

Commit 9564b95

Browse files
authored
Create create-model-save-query-scaffold-efc6.cs
1 parent 28d82a0 commit 9564b95

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace OracleEFCore6
4+
{
5+
class Program
6+
{
7+
//This sample code demonstrates how to get started with Oracle Entity Framework Core 6
8+
//It can connecto to on-premises Oracle DB or walletless Oracle Autonomous DB
9+
10+
public class BloggingContext : DbContext
11+
{
12+
public DbSet<Blog>? Blogs { get; set; }
13+
public DbSet<Post>? Posts { get; set; }
14+
15+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
16+
{
17+
optionsBuilder.UseOracle(@"User Id=blog;Password=<Password>;Data Source=<Net Service Name");
18+
}
19+
}
20+
21+
public class Blog
22+
{
23+
public int BlogId { get; set; }
24+
public string? Url { get; set; }
25+
//public int? Rating { get; set; }
26+
public List<Post>? Posts { get; set; }
27+
}
28+
29+
public class Post
30+
{
31+
public int PostId { get; set; }
32+
public string? Title { get; set; }
33+
public string? Content { get; set; }
34+
35+
public int BlogId { get; set; }
36+
public Blog? Blog { get; set; }
37+
}
38+
39+
static void Main(string[] args)
40+
{
41+
42+
using (var db = new BloggingContext())
43+
{
44+
var blog = new Blog { Url = "https://blogs.oracle.com" };
45+
//var blog = new Blog { Url = "https://blogs.oracle.com", Rating = 10 };
46+
db.Blogs!.Add(blog);
47+
db.SaveChanges();
48+
}
49+
50+
using (var db = new BloggingContext())
51+
{
52+
var blogs = db.Blogs;
53+
foreach (var item in blogs!)
54+
{
55+
Console.WriteLine(item.Url);
56+
//Console.WriteLine(item.Url + " has rating " + item.Rating );
57+
}
58+
}
59+
Console.ReadLine();
60+
}
61+
}
62+
}
63+
64+
65+
/* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. */
66+
67+
/******************************************************************************
68+
*
69+
* You may not use the identified files except in compliance with The MIT
70+
* License (the "License.")
71+
*
72+
* You may obtain a copy of the License at
73+
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
74+
*
75+
* Unless required by applicable law or agreed to in writing, software
76+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
77+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78+
*
79+
* See the License for the specific language governing permissions and
80+
* limitations under the License.
81+
*
82+
*****************************************************************************/

0 commit comments

Comments
 (0)