Skip to content

Commit 6a2b055

Browse files
committed
2 parents f34ae02 + f49ab89 commit 6a2b055

6 files changed

Lines changed: 61 additions & 9 deletions

File tree

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Upload Documentation
3636
if: success()
37-
uses: actions/upload-pages-artifact@v4
37+
uses: actions/upload-pages-artifact@v5
3838
with:
3939
name: github-pages
4040
path: "site/"
@@ -51,7 +51,7 @@ jobs:
5151
steps:
5252
- name: Deploy Documentation
5353
id: deployment
54-
uses: actions/deploy-pages@v4
54+
uses: actions/deploy-pages@v5
5555

5656
environment:
5757
name: github-pages

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272
- name: Upload Packages
7373
if: success() && github.event_name != 'pull_request'
74-
uses: actions/upload-artifact@v6
74+
uses: actions/upload-artifact@v7
7575
with:
7676
name: packages
7777
path: "${{env.BUILD_PATH}}"

.github/workflows/merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- name: Dependabot Metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v2
16+
uses: dependabot/fetch-metadata@v3
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

sample/Tracker/Tracker.Web/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using AutoMapper;
1+
using AutoMapper;
22
using FluentValidation;
33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.AspNetCore.Hosting;
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.DependencyInjection;
88
using Microsoft.Extensions.Hosting;
9-
using Microsoft.OpenApi.Models;
9+
using Microsoft.OpenApi;
1010
using Tracker.Core.Data;
1111

1212
namespace Tracker.Web
@@ -28,7 +28,7 @@ public void ConfigureServices(IServiceCollection services)
2828
services.AddDbContext<TrackerContext>(options => options.UseSqlServer(connectionString));
2929

3030
// register AutoMapper profiles
31-
services.AddAutoMapper(typeof(TrackerContext));
31+
services.AddAutoMapper(cfg => { }, typeof(TrackerContext).Assembly);
3232

3333
// register validation
3434
services.Scan(x =>

src/EntityFrameworkCore.Generator.Core/ModelGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ private void GetModels(Entity? entity)
514514

515515
if (_options.Model.Read.Generate)
516516
CreateModel(entity, _options.Model.Read, ModelType.Read);
517-
if (_options.Model.Create.Generate)
517+
if (!entity.IsView && _options.Model.Create.Generate)
518518
CreateModel(entity, _options.Model.Create, ModelType.Create);
519-
if (_options.Model.Update.Generate)
519+
if (!entity.IsView && _options.Model.Update.Generate)
520520
CreateModel(entity, _options.Model.Update, ModelType.Update);
521521

522522
if (entity.Models.Count > 0)

test/EntityFrameworkCore.Generator.Core.Tests/ModelGeneratorTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33

4+
using EntityFrameworkCore.Generator.Metadata.Generation;
45
using EntityFrameworkCore.Generator.Options;
56

67
using Microsoft.Extensions.Logging.Abstractions;
@@ -94,6 +95,57 @@ public void GenerateModelsCheckNames()
9495

9596
}
9697

98+
[Fact]
99+
public void GenerateViewModelsSkipsCreateAndUpdateModels()
100+
{
101+
var generatorOptions = new GeneratorOptions();
102+
generatorOptions.Model.Read.Generate = true;
103+
generatorOptions.Model.Create.Generate = true;
104+
generatorOptions.Model.Update.Generate = true;
105+
106+
var databaseModel = new DatabaseModel
107+
{
108+
DatabaseName = "TestDatabase",
109+
DefaultSchema = "dbo"
110+
};
111+
var testView = new DatabaseView
112+
{
113+
Database = databaseModel,
114+
Name = "TestView",
115+
Schema = "dbo"
116+
};
117+
databaseModel.Tables.Add(testView);
118+
119+
var identifierColumn = new DatabaseColumn
120+
{
121+
Table = testView,
122+
Name = "Id",
123+
IsNullable = false,
124+
StoreType = "int"
125+
};
126+
testView.Columns.Add(identifierColumn);
127+
128+
var nameColumn = new DatabaseColumn
129+
{
130+
Table = testView,
131+
Name = "Name",
132+
IsNullable = true,
133+
StoreType = "varchar(50)"
134+
};
135+
testView.Columns.Add(nameColumn);
136+
var generator = new ModelGenerator(NullLoggerFactory.Instance);
137+
138+
var typeMappingSource = CreateTypeMappingSource();
139+
140+
var result = generator.Generate(generatorOptions, databaseModel, typeMappingSource);
141+
Assert.Single(result.Entities);
142+
143+
var firstEntity = result.Entities[0];
144+
Assert.True(firstEntity.IsView);
145+
Assert.Single(firstEntity.Models);
146+
Assert.Equal(ModelType.Read, firstEntity.Models[0].ModelType);
147+
}
148+
97149
[Fact]
98150
public void GenerateWithSymbolInDatabaseName()
99151
{

0 commit comments

Comments
 (0)